asp.net - Is MemoryCache scope session or application wide? -
i'm using memorycache
in asp.net , working well. have object cached hour prevent fresh pulls of data repository.
i can see caching working in debug, once deployed server, after 1st call made , object cached subsequent calls 1/5 of time.
however i'm noticing each new client call (still inside 1 hour window - in fact minute or 2 later) seems have 1st call service (that doing caching) taking long original call before data cached.
this made me start wonder - memorycache
session specific, , each new client making call storing it's own cache, or else going on cause 1st call take long after know data has been cached?
from msdn:
the main differences between cache , memorycache classes memorycache class has been changed make usable .net framework applications not asp.net applications. example, memorycache class has no dependencies on system.web assembly. difference can create multiple instances of memorycache class use in same application , in same appdomain instance.
reading , doing investigation in reflected code obvious memorycache
simple class. can use memorycache.default
property (re)use same instance or can construct many instances want (though recommended few possible).
so answer lies in code.
if use memorycache.default
cache lives long application pool lives. (just remind default application pool idle time-out 20 minutes less 1 hour.)
if create using new memorycache(string, namevaluecollection)
above mentioned considerations apply plus context create instance in, if create instance inside controller (which hope not case) cache lives 1 request
it's pity can't find references, ... memorycache
not guarantee hold data according cache policy specify. in particular if machine you're running app on gets stressed on memory cache might discarded.
if still have no luck figuring out what's reason cache item invalidation take advantage of removecallback
, investigate reason of item invalidation.
Comments
Post a Comment