Caching Problem -
01-19-2005
, 10:39 PM
Hi
I want to use the System.Web.Caching.Cache instance returned by
HttpContext.Current.Cache to cache a few objects.
I only seem to be able to get this working as intended with those objects
which only depend on a single file dependency. In other words, each object
added with a
new CacheDependency (new string [] { filePath })
works just fine. However, some objects not only depend on their backing file
but also on other objects that are already in the cache (I make sure their
dependencies are in the cache before attempting to add them). In this case I
use a
new CacheDependency (new string [] { filePath }, cacheKeys)
where cacheKeys is an array that always (I double-checked) gets populated
correctly prior to constructing the dependency object.
Whenever I use this kind of constructor, the object, even though it is never
null, is not added to the Cache! All these objects use
CacheItemPriority.NotRemovable (just for testing's sake), the expiration
date is far in the future, no sliding expiration, their backing files have
not been changed at all, etc. - it's just when the dependency specifies a
file path AS WELL AS an additional cache key. And only in these cases.
Assume the object "doc", which is not null.
I call
Cache.Add (key, doc, dependencyObj, etcpp...)
and then, immediately afterwards:
object o = Cache [key]
In the scenario described above, o is always null! Otherwise (with just a
filepath and no additional cache key dependency), it is just the correct
instance.
Ever had to deal with such behaviour?
Any ideas are greatly appreciated,
Many thanks!
Philipp Schumann |