Cancellazione di un elemento dalla cache di precaricamento in 9.2
Abbiamo basato la nostra implementazione su Cancella cache Sitecore per un elemento dalla cache a livello di codice per cancellare un elemento dalla cache di prefetch come di seguito
Cache prefetchCache = GetPrefetchCache(Database database);
prefetchCache.RemoveKeysContaining(itemID.ToString());
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;
}
}
}
Ma la classe Cache di 8.2 è stata modificata in ICacheInfo in 9.2 e RemoveKeysContain non è disponibile. C'è un modo per rimuovere un particolare elemento da prefetchCache in 9.2
Risposte
Sitecore ha modificato l'implementazione in ICacheInfo
. Tuttavia, puoi ancora utilizzare il metodo RemoveKeysContaining
nella cache dopo aver applicato il casting Sitecore.Caching.Cache.
L' ICacheInfo
ha implementazioni multiple e la classe Cache
è uno dei implementazione.
Si prega di vedere sotto lo snippet di codice:
Cache prefetchCache = GetPrefetchCache(database);
//Check for null before applying method
if (prefetchCache != null)
{
prefetchCache.RemoveKeysContaining(itemID.ToString());
}
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 as Cache;
}
}
}
Si noti che la cache proviene dallo spazio dei nomi Sitecore.Caching.Cache
dall'assemblySitecore.Kernel.dll