Value stored in session depends on value in HttpRuntime cache

832 Views Asked by At

I have data common for all users stored in HttpRuntime.Cache.

Then I have some user related data stored in Session.

HttpRuntime.Cache has CacheDependency mechanism, which can be used to define relationships between the items in cache.

What would you use to handle the dependency between Session and Runtime Cache?

Additional to CacheDependencies, there is also CacheItemRemovedCallback. I could remove specific values from each session during this callback, if it's even possible.

1

There are 1 best solutions below

2
On BEST ANSWER

The cache dependency works the other way, i.e. when the cache is dependent on something else, not when something is dependent on the cache.

Using the CacheItemRemovedCallback to update items in the Session object is not possible. The callback is not called in the scope of a specific user, so you can't access the Session object. You would have to keep the data somewhere else, so that you can access the data for all users, as the data depending on the item removed from the cache may belong to any user.