Caching Help Needed

A

Aryan

Hi,
I have problem related to Caching of data. I am reading large xml
file and putting this xml in dataset, since this dataset will contain
many datatable's inside. And each datatable might be big in data. Each
user will contain its seperate xml file, so when I create xml file for
each user, I am putting this xml DataSet in Cache object, but when I
try to populate my controls using Cache object, I am faching weired
problem. As some times it populates the controls and some times it
doesnt, although the xml files have been created for that user.
Along with this I am using same cache object name for every user.

So please tell me what could be the reason for cache is not able to
populate the controls on some time.???and what could be best usage for
concurrent users??Sessions or Cache??

Thanks in Advance.
Manoj Singh
 
N

Nicholas Paldino [.NET/C# MVP]

Manoj,

The cache has a scope of an application, so if you have a key such as
"xmlFile" for the cache, then you will be reading/writing to it for all of
the users, which I don't think is what you want.

Rather, you should attach a unique identifier for the user to the end of
the "xmlFile" to make sure that each user has their own version of the
cache, like so:

// Make the key.
private const string XmlFileKeyFormat = "xmlFile_{0}";

private static string GetXmlFileKey(string userId)
{
// Perform error checking against user id here.

// Format the string.
return string.Format(XmlFileKeyFormat, userId);
}

public static XmlDocument GetXmlFile(string userId)
{
// Return the xml file.
return (XmlDocument) HttpContext.Current.Cache[GetXmlFileKey(userId)];
}

public static void SetXmlFile(string userId, XmlDocument document)
{
// Set the document.
HttpContext.Current.Cache[GetXmlFileKey(userId)] = document;
}

Hope this helps.
 
S

sloan

Per User = Session
Everybody = Cache

That's the simple formula.

You could uniquely name files/keys for the Cache, but that feels weird. But
I guess its how long you want to Cache it.


You might want to check out
http://sholliday.spaces.live.com/ 10/24/2005 entry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top