views:

105

answers:

1

I would like to ask is there any way to achieve this functionality:

I have an Ajax enabled user web site (tree view on the left side, and content on the right side). When users selects a node on the left side, I need to store the last selected node in database. However the user can change the node quite often (even 5 or 10 times a minute).

So I would like to add it to the application cache, like:

cache["userName"]=selectedNodeID;

Is there any caching framework that would: perform certain action on a cache item if it wasn't changed for let's say 5 minutes? It would allow me to store last selected node id after 5 minutes from last change. If the user changes the node before this time passes - I would just update cache value and reset timer.

Any hints?

+4  A: 

You could use the callback mechanism for when the cache item is removed from the cache. If you set the cache duration to 5 minutes, then you could check in your callback method whether the item has already been saved - if it hasn't then you can push it to the database. In either case, you can put the item straight back in the cache for another 5 minutes.

e.g. you would have something like this as the last parameter of your Cache.Insert method:

new CacheItemRemovedCallback (SaveItemToDatabaseAndReturnItToTheCache)

and then you would implement the callback method accordingly.

more info here: http://weblogs.asp.net/kwarren/archive/2004/05/20/136129.aspx

Steve Willcock
Thanks for the answer, it works!
Adam