Just like the topic says. I have a DLL that provides a DAL, and I’d like to get it to start caching in specific instances.
The mentioned DLL is used both in an asp.net application, and a console application.
What I’d like to do is use the System.Runtime.Caching namespace, but I want the caching to be purged at the end of every request for the asp.net environment. The point is to make sure I’m not going back to the DB multiple times for the same data over a single request, I’m not looking for a generic caching mechanism for data that needs to survive over multiple requests.
I can’t really seem to find anything on this particular aspect of System.Runtime.Caching. What does it use in the asp.net context, and is there a way for me to get it to do this?
I realize I could just use a static member somewhere, but I would prefer not doing it that way since it isn’t as future proof.
Its all in the cache keys you make and the expiration period. In your example, you will want to provide a sliding expiration (where if the item is untouched, it is removed from cache after the elapsed period).
The cache key should have some session/request specific ID as part of it.
It does seem odd that you would only be caching on a per-request basis and not a per-user or per-system basis. You may want to explore other forms of data sharing like thread local storage.