我想以编程方式清除项目的Sitecore缓存。我运行下面的代码。之后,我尝试在已删除的ID上执行web.GetItem,我仍然得到null。有什么建议吗?
Database db = new Database("web");
if (ID.IsID(id))
{
ID itemID = new ID(id);
//clear data cache
db.Caches.DataCache.RemoveItemInformation(itemID);
//clear item cache
db.Caches.ItemCache.RemoveItem(itemID);
//clear standard values cache
db.Caches.StandardValuesCache.RemoveKeysContaining(itemID.ToString());
//remove path cache
db.Caches.PathCache.RemoveKeysContaining(itemID.ToString());
}
答案 0 :(得分:5)
看起来你错过了预取缓存,以下是如何获取它:
private Cache GetPrefetchCache(Database database)
{
foreach (var cache in global::Sitecore.Caching.CacheManager.GetAllCaches())
{
if (cache.Name.Contains(string.Format("Prefetch data({0})", database.Name)))
{
return cache;
}
}
html缓存也是:
private void ClearAllHtmlCaches()
{
foreach (var info in Factory.GetSiteInfoList())
{
info.HtmlCache.Clear();
}
}