Need Help With Design Considerations and Caching Block

Topics: Caching Application Block , Data Access Application Block
Jun 25, 2009 at 1:54 AM

I have a service that will maintain a static list of data in memory that needs to be accessible whenever a client makes a SOAP call to this service. So the same list will be shared between all users. This list will be added to as new clients make new requests. This in-memory data needs to be protected from the web service crashing or power failures etc so I need to keep a realtime copy of the list in a data store and restore it in case of failure. I thought I could use the Enterprise Caching Block with a database backing store, but I have the caching object implemented with a backing store and now I'm not sure it is what I want.

Does anyone have any suggestions about how they would do this?

For the caching block is there a way to turn the expiration off? I plan on removing the item from the list when it is no longer need. I also need a way of restoring the cache from the database when the application is brought back up but I can't find a way to do that.

Thanks

Jun 25, 2009 at 3:31 AM
Edited Jun 25, 2009 at 3:35 AM

From what you've mentioned, you should indeed use a database backing store.

When using a database backing store, it automatically loads the cache items when the cache manager is created.  What problems are you encountering which have you arrive at the conclusion that you can't restore the cache from the database?

Regarding on how to turn expiration off, you can add items and pass a NeverExpired CacheItemExpiration.  

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jun 25, 2009 at 2:47 PM

Thank you very much, you have answered all of my questions.

"What problems are you encountering which have you arrive at the conclusion that you can't restore the cache from the database?"

    I was looking for a reload from database flag in the constructor or something like that, I didn't realize it would be automatic.

 

Jun 26, 2009 at 1:36 AM

Can you explain a bit about how the CacheItemPriority works?

I found this table in a bing search.

Value Description
High High priority for scavenging, meaning that the items with this priority level are the least likely to be deleted from the cache as the server frees the system memory.
Low Low priority for scavenging, meaning that the items with this priority are the most likely to be deleted from the cache as the server frees the system memory.
None No priority associated with scavenging.
Normal Normal priority for scavenging, meaning that the items with this priority are likely to be deleted from the cache as the server frees the system memory only after those items with the "Low" priority.
NotRemovable

Non-removable priority for scavenging, meaning that these items are not automatically deleted from the cache as the server frees the system memory. However, even items with this priority are removed according to the item's absolute or sliding expiration time.

What happens when a cache item is removed from memory? Is it just stored in the database and retreived from the DB automatically by the CacheManager if that particular cache item is called on again by passing its key to the GetData method?

Thanks

Jun 26, 2009 at 6:00 AM

Hi.

Please see this, http://msdn.microsoft.com/en-us/library/dd139967.aspx tell something about the scavenging process and CacheItemPriority.

The Item deleted from the cache will is permanently removed. Unless you add it again to the cache, passing its key to the GetData method will result to a null value.

Valiant Dudan
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jun 26, 2009 at 2:17 PM
Edited Jun 26, 2009 at 2:47 PM

Thanks, I have already read that article, I just wasn't clear if "removed from cache" meant from memory and the backing store or not.

So far from all I have read, since I want to decide when something is removed from cache based on actions from the end user (the end user tells me when they are done) I am thinking I will use a "Not Removable" priority. The items in the cache could literally be in there waiting for the user to finish using them for weeks.

Incidentally, is there a way to tell it to remove from memory but not the backing store? If someone leaves their session for a few weeks I would like it to just fall back to the backing store and free up memory.

Thanks

Jun 29, 2009 at 4:22 AM

CAB was not designed to support that scenario, it is implemented such as that the in-memory cache and the database backing store is always synchronized.  If you add something, it adds to the in-memory cache as well as to the persistent backing store.  If it removes an item, it removes from both.  Scavenging is not an exception, the process removes the items from both storage.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com