Note that there are some explanatory texts on larger screens.

plurals
  1. POMemoryCache does not work after several minutes
    text
    copied!<p>Here is my code:</p> <pre><code>public class ConfigCache { private static volatile ObjectCache _cache = MemoryCache.Default; private const string KeyModule = "MODULE_XDOC_KEY"; private static string _settingFile; public ConfigCache(string file) { _settingFile = file; } public XDocument Get() { var doc = _cache[KeyModule] as XDocument; if (doc == null) { doc = XDocument.Load(_settingFile); var policy = new CacheItemPolicy(); var filePaths = new List&lt;string&gt; {_settingFile}; policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); var callback = new CacheEntryRemovedCallback(this.MyCachedItemRemovedCallback); policy.RemovedCallback = callback; _cache.Set(KeyModule, doc, policy); } return _cache[KeyModule] as XDocument; } private void MyCachedItemRemovedCallback(CacheEntryRemovedArguments arguments) { // Log these values from arguments list } } </code></pre> <p>When run into _cache.Set() first time, it works fine:</p> <ul> <li>_cache.Set() works well, it add the xdoc into cache.</li> </ul> <p>But after several minutes(1 or 2 minutes), cache will not work anymore:</p> <ul> <li>_cache.Set() does not insert anything into cache</li> <li>_cache.Set() does not report any error.</li> <li>the callback MyCachedItemRemovedCallback never triggered.</li> </ul> <p>Someone met same issue: <a href="https://stackoverflow.com/questions/10254708/memorycache-always-returns-null-after-first-expiration">MemoryCache always returns &quot;null&quot; after first expiration</a></p> <p>But it seems not resolved yet. Anyone have any idea on this?</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