Note that there are some explanatory texts on larger screens.

plurals
  1. POCache is removing after add object to cache
    text
    copied!<p>I develop asp.net web forms application in VS2012 a I have one project with Web.App and one project is a Class Library. In a class library i reading configuration from web.config (in a project is a lot of app settings like path for menu file, log file etc...) and in this assembly i have a class for caching and logging events to file.</p> <p>This is a part of cache class:</p> <pre><code>public static class MyCache { public const String CACHE_MENU_USER = "CACHE_MENU_USER_{0}"; public const String CACHE_LOG_FILE_PATH = "LOG_FILE_PATH"; public static void AddToCache(String cacheKey, Object value, DateTime absoluteExpiration, bool loggToFile = true) { HttpContext.Current.Cache.Add(cacheKey, value, null, absoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.High, (k, v, r) =&gt; //key, value, reason of remove from cache { String reasonOfRemove = String.Empty; switch (r) { case CacheItemRemovedReason.DependencyChanged: reasonOfRemove = String.Format("CacheItemRemovedReason.DependencyChanged"); break; case CacheItemRemovedReason.Expired: reasonOfRemove = String.Format("CacheItemRemovedReason.Expired"); break; case CacheItemRemovedReason.Removed: reasonOfRemove = String.Format("CacheItemRemovedReason.Removed"); break; case CacheItemRemovedReason.Underused: reasonOfRemove = String.Format("CacheItemRemovedReason.Underused"); break; } AppConfiguration.Logger.WriteMessage(String.Format("Key {0} was removed for reason: {1}", cacheKey, reasonOfRemove)); }); if (loggToFile) AppConfiguration.Logger.WriteMessage(String.Format("Insert cache key {0} from now to: {1}", cacheKey, absoluteExpiration)); } } </code></pre> <p>AppConfiguration is a static class with static properties with values from web.config. Logger is a instance of Logger class.</p> <p>In global.asax is a piece of code:</p> <pre><code>protected void Application_Start(object sender, EventArgs e) { AppConfiguration.ReadConfiguration(); AppConfiguration.Logger.WriteMessage("Start app"); } protected void Application_End(object sender, EventArgs e) { AppConfiguration.Logger.WriteMessage("End app"); } </code></pre> <p>Problem is, that App_Start is called on every request a inserted value to cache is immediately removed...</p> <p>this is a part of log file:</p> <p>10.8.2013 17:14:22: Start app.</p> <p>10.8.2013 17:14:23: Insert cache key CACHE_MENU_USER_DEMO\Administrator from now to: 8/17/2013 5:14:23 PM</p> <p>10.8.2013 17:14:23: Key CACHE_MENU_USER_DEMO\Administrator was removed for reason: CacheItemRemovedReason.Removed</p> <p>10.8.2013 17:14:23: End app.</p> <p>a this is repeated with every request. </p> <p>I was trying start application in IIS Express, i trying start application in server (IIS7, Windows server 2008 R2) and it is still the same...</p> <p>Any idea what is wrong with cache and global.asax? Thanks</p> <p><strong>EDIT:</strong> *<em>Problem solved. More is in comments from FlopScientist</em>*</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload