Caching strategy for asp.net
I would like to ask if there is a way to achieve this functionality:
I have a custom website with Ajax enabled (tree view on the left and content on the right side). When users select a node from the left side, I need to store the last selected node in the database. However, the user can change node frequently (even 5 or 10 times per minute).
So I would like to add it to the application cache, for example:
cache["userName"]=selectedNodeID;
Is there any caching infrastructure that: would perform certain actions on a cache item if it hadn't been changed, let's say 5 minutes? This would allow me to keep the last selected node id 5 minutes after the last change. If the user modifies the node before this time - I would just update the cache value and reset the timer.
Any hints?
a source to share
You can use a callback mechanism when a cache item is removed from the cache. If you set the cache duration to 5 minutes, you can check your callback method to see if the item has already been saved - if it doesn't, then you can push it to the database. Either way, you can put the item back into the cache for another 5 minutes.
eg. you have something like this as the last parameter of your Cache.Insert method:
new CacheItemRemovedCallback (SaveItemToDatabaseAndReturnItToTheCache)
and then you implement the callback method appropriately.
more details here: http://weblogs.asp.net/kwarren/archive/2004/05/20/136129.aspx
a source to share