CollectionBase in the Cache

G

Grant Merwitz

Hi

I am trying to Cache an Object that inherits from CollectionBase.

My logic here, is when the Object is instantiated, try retrieve its data out
the Cache, if its null, retrieve the data from its source (Xml file).

Now i'm not sure what to Cache, or what to retrieve.

I've tried
this.InnerList = HttpContext.Current.Cache["MyCacheName"];

But as this InnerList is read-only, i cannot so this.

So:
What should i Cache/Retrieve to get this working

TIA
 
K

Karl Seguin

Why not cache the object itself "this"?

public static MyObject GetInstance()
{
MyObject instance = (MyObject)Cache["MyCacheName"];
if (instance == null)
{
instance = GetFromYourXMlFile();
Cache.Insert("MyCacheName", instance,whatever, whatever,whatever);
}
return instance;
}


Karl
 
G

Grant Merwitz

Thanks, Thats not a bad idea

What i did end up doing, is using the AddRange method to push it into an
ArrayList,
then Cached that


Karl Seguin said:
Why not cache the object itself "this"?

public static MyObject GetInstance()
{
MyObject instance = (MyObject)Cache["MyCacheName"];
if (instance == null)
{
instance = GetFromYourXMlFile();
Cache.Insert("MyCacheName", instance,whatever, whatever,whatever);
}
return instance;
}


Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


Grant Merwitz said:
Hi

I am trying to Cache an Object that inherits from CollectionBase.

My logic here, is when the Object is instantiated, try retrieve its data
out the Cache, if its null, retrieve the data from its source (Xml file).

Now i'm not sure what to Cache, or what to retrieve.

I've tried
this.InnerList = HttpContext.Current.Cache["MyCacheName"];

But as this InnerList is read-only, i cannot so this.

So:
What should i Cache/Retrieve to get this working

TIA
 

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