Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net CacheDependency object question

I think I know the answer to this but I cannot find a definitive yes or no anywhere in documentation or articles.

Using .Net 3.5 ASP.Net caching, if you make a CacheDependency passing a string[] of cacheKeys, do those passed cacheKeys get inserted into the cache on the Insert in which the dependency is used on if they do not already exist?

CacheDependency dependency = 
    new CacheDependency(null, new string[] { "abc", "def", "ghi"});
HttpRuntime.Cache.Insert("123", "xxx", dependency);

So when cache item "123" gets inserted, what if there isn't already an item in cache with the key "def"? Does it then get created?

If not, is there a way to then take that CacheDependency object, and find out what keys it was created with, so I can then loop thru them and add each as needed?

Basically, I trying to allow a CacheDependency object to be passed into my custom CacheManager object methods for dependencies instead of the string[] array I require now. Thanks for any help you can provide.

like image 386
Billyhole Avatar asked Nov 24 '10 20:11

Billyhole


1 Answers

The answer is no. The cacheKeys of a cacheDependency that are not already in cache ARE NOT inserted into the cache on the Insert of the item in which the dependency is used.

In fact, the actual item being Inserted with the dependency does not even make it into the cache because its dependency does not already exist in cache.

like image 123
Billyhole Avatar answered Oct 28 '22 03:10

Billyhole