嗨,
我创建了一个自定义列表,它试图缓存,但是从缓存中返回时,缓存的对象计数为 0。示例代码如下:
List<CategoryEntry> categs = (List<CategoryEntry>)EPiServer.CacheManager.Get("test");
if(categs == null || categs.Count == 0)
{
categs = ConstructCategories();
EPiServer.CacheManager.Add("test", categs);
}
//Further down displaying the categories
用例:
第一个页面加载(构建后)缓存为空,类别将为空,
第二个页面加载缓存将是,但将从那里获取失败,因为categs.Count will be 0
并一次又一次地重建缓存....
CategoryEntry 类:
[serializable]
public class CategoryEntry{
public string Title { get; set; }
public string URL { get; set; }
public int CategoryId { get; set; }
public int CompanyPageId { get; set; }
public int ParentCategoryEntryId { get; set; }
public int Indent { get; set; }
}
问题应该是保存缓存 bc 时。它被保存为object
,当我们得到我们 Cast 的缓存时List<CategoryEntry>
。
还想通了,如果我用 aList<string>
而不是使用,List<CategoryEntry>
那么缓存工作得很好!
正在使用的示例List<string>
:
List<string> test = (List<string>)EPiServer.CacheManager.Get("sindex");
if (test == null)
{
test = new List<string>();
test.Add("item1");
test.Add("item2");
test.Add("item3");
test.Add("item4");
test.Add("item5");
EPiServer.CacheManager.Add("sindex", test);
}
else
{
Response.Write("It works: elements "+ test.Count);
}
另一个试用是我已经缓存了一个简单的实例CategoryEntry
并且它也有效,问题是当我尝试另存为时List<CategoryEntry>
任何帮助将不胜感激,谢谢。