c# - How to make ASP.NET Application Cache Persistent -
if add asp.net application cache, persistent or re-load on interval?
httpcontext.current.application["mykeyname"] = "some data";
will "mykeyname" exist until end of application's life?
also, application cache available sessions correct? meaning, once loads once first user, doesn't have load again rest of users.
per msdn:
using application cache similar using application state. however, unlike application state, data in application cache volatile, meaning not stored in memory life of application. advantage of using application cache asp.net manages cache , removes items when expire or become invalidated, or when memory runs low. can configure application caching notify application when item removed. more information see caching application data.
the example code provided
httpcontext.current.application["mykeyname"] = "some data";
is using application state, not using application cache. application state has many disadvantages application cache - namely lost when application pool recycles, not thread-safe, there no way make cache expire, , there no cache dependency mechanism make update automatically if underlying data store updated. application state considered antiquated caching technology. see application state considerations more details.
to use application cache, access through httpcontext.cache
property. note in mvc httpcontext
available in places, should avoid using static httpcontext.current
accessor.
// var value = this.httpcontext.cache["mykeyname"]; // set this.httpcontext.cache.insert( "mykeyname", value, null, datetime.now.addminutes(5), system.web.caching.cache.noslidingexpiration, system.web.caching.cacheitempriority.notremovable, null);
there new caching option in .net 4: system.runtime.caching
, similar application cache, not have dependencies on system.web
namespace.
Comments
Post a Comment