c# - How to inspect cache policies inside System.Runtime.Caching.ObjectCache? -


i'm making use of new .net 4.0 caching namespace: system.runtime.caching.

now, i'm doing prototype/fiddling new api, in order work out best fit real app.

in line that, i'm trying create page (asp.net mvc) dumps out in cache, particularly following info:

  • cache key
  • cache object
  • cache policy (expiry date, etc)
  • cache dependencies (if any)

however, can't seem except key/object.

here's code i'm playing with:

public actionresult index() {    var cache = memorycache.default;     // can list of cache keys this:    var cachekeys = cache.select(kvp => kvp.key).tolist();     // can strongly-typed "cacheitem" this:    cacheitem item = cache.getcacheitem("somekey");  } 

i have hoped "cacheitem" class expose information require (expiry, dependencies, etc - @ least "getters").

but doesn't. has properties key, value , region name.

how can inspect items in cache , spit out information require?

is there namespace/class i'm missing?

edit

looks there changemonitor class, again - doesn't give expiration info, allows subscribe events when cache items removed.

there must way grab items in cache, , when expire.

edit 2

don't know if should seperate question, - i'm confused lifetime should give objectcache. msdn says it's not singleton, , can in fact create multiple objectcache instances. mean though, have use fully-locked singleton when accessing objectcache instance?

it doesn't me there way retrieve cacheitempolicy once it's been added cache collection.

the best way around can think of cache policy object along item want cache appending "policy" key name can later retrieve policy. assumes have control on adding item cache in first place. example below:

public actionresult index()     {         string key = "hello";         string value = "world";          var cache = memorycache.default;         cacheitempolicy policy = new cacheitempolicy();         policy.absoluteexpiration = datetime.now.adddays(1);         cache.add(new cacheitem(key, value), policy);         cache.add(new cacheitem(key + "policy", policy), null);          cacheitem item = cache.getcacheitem(key);         cacheitem policyitem = cache.getcacheitem(key + "policy");         cacheitempolicy policy2 = policyitem.value cacheitempolicy;          viewbag.message = key + " " + value;          return view();     } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -