caching - When Does Asp.Net Remove Expired Cache Items? -


when add item system.web.caching.cache absolute expiration date, in following example, how asp.net behave? it:

  1. simply mark item expired, execute cacheitemremovedcallback on next access attempt?

  2. remove item cache , execute cacheitemremovedcallback immediately?

    httpruntime.cache.insert(key,                          new object(),                          null,                           datetime.now.addseconds(seconds),                           cache.noslidingexpiration,                          cacheitempriority.notremovable,                           oncacheremove); 

msdn appears indicate happens immediately. example, the "expiration" section of "asp.net caching overview" says "asp.net automatically removes items cache when expire." similarly, example topic "how to: notify application when item removed cache" says "if more 15 seconds elapses between calls getreport [a method in example], asp.net removes report cache."

still, neither of these unambiguous. don't "the callback executed immediately" , conceive of how writers might have thought option 1 above counts 'removing' item. did quick , dirty test, , lo, appears executing - regular sixty-second callbacks when no 1 accessing site.

nonetheless, test quick , dirty, , in comments answer is there way run process every day in .net web application without writing windows service or sql server jobs, has suggested asp.net defers removal , execution of callback until tries access cache again.

can settle authoritatively or considered implementation detail?

hurray reflector!

expired cache items actually removed (and callbacks called) when either:

1) tries access cache item.

2) expiresbucket.flushexpireditems method runs , gets item. method hard-coded execute every 20 seconds (the accepted answer stackoverflow question changing frequency of asp.net cache item expiration corroborates read of code via reflector). however, has needs additional qualification (for read on).


asp.net maintains 1 cache each cpu on server (i'm not sure if these represent logical or physical cpus); each of these maintains cacheexpires instance has corresponding timer calls flushexpireditems method every twenty seconds.

this method iterates on collection of 'buckets' of cache expiration data (an array of expiresbucket instances) serially, calling each bucket's flushexpireditems method in turn.

this method (expiresbucket.flushexpireditems) first iterates cache items in bucket , if item expired, marks expired. (i'm grossly simplifying here) iterates items has marked expired , removes them, executing cacheitemremovedcallback (actually, calls cachesingle.remove, calls cacheinternal.doremove, cachesingle.updatecache, cacheentry.close, calls callback).

all of happens serially, there's chance block entire process , hold things (and push cache item's expiration specified expiration time).

however, @ temporal resolution, minimum expiration interval of twenty seconds, part of process block significant length of time execution of cacheitemremovedcallbacks. 1 of these conceivably block given timer's flushexpireditems thread indefinitely. (though twenty seconds later, timer spawn flushexpireditems thread.)

to summarize, asp.net not guarantee execute callbacks @ specified time, under conditions. long expiration intervals more twenty seconds apart, , long cache doesn't have execute time-consuming cacheitemremovedcallbacks (globally - callbacks potentially interfere others), can execute expiration callbacks on schedule. enough applications, fall short others.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -