EnterpriseLibrary CacheManager在应用程序重启后消失了吗?

时间:2012-03-06 23:24:42

标签: c# wpf caching enterprise-library

我有一个C#WPF应用程序。我最近发现了Microsoft Enterprise Library Caching选项。

我在应用程序中添加了以下代码:

ICacheManager oCacheManager = CacheFactory.GetCacheManager();
if (!oCacheManager.Contains("TESTING"))
{
    //
    // Code which populates myDictionary object
    //

    oCacheManager.Add("TESTING", myDictionary);

    if (oCacheManager.Contains("TESTING")) 
        Console.WriteLine("Stored!");
}
else  // below never gets hit
{
    Console.WriteLine("Found It!");
    CachedObjects = (Dictionary<string, object>)oCacheManager.GetData("TESTING");
}

每次运行应用程序时,它都会输出“Stored!”。它永远不会输出“Found It!”。这意味着每次应用程序关闭时都会抛出缓存。有没有办法坚持下去,以便每次后续启动它都会找到缓存并加载它?

由于

1 个答案:

答案 0 :(得分:0)

缓存对象的默认存储是NullBackingStore,这实际上意味着该对象仅缓存在内存中。其他选项是IsolatedStorageBackingStore(写入用户隔离存储中的磁盘)和DatabaseBackingStore(写入数据库)。这两个都比NullBackingStore慢得多,但数据将在重启后保留。

相关问题