การล้างรายการจาก Prefetch Cache ใน 9.2

Aug 21 2020

เราได้ใช้การใช้งานของเราในการล้างแคช Sitecore สำหรับรายการจากแคชโดยทางโปรแกรมเพื่อล้างรายการจากการดึงข้อมูลแคชล่วงหน้าดังต่อไปนี้

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;
            }
        }
    }  

แต่คลาสแคชของ 8.2 ถูกแก้ไขเป็น ICacheInfo ใน 9.2 และ RemoveKeysContaining ไม่พร้อมใช้งาน มีวิธีใดบ้างในการลบรายการใดรายการหนึ่งออกจาก prefetchCache ใน 9.2

คำตอบ

1 HishaamNamooya Aug 21 2020 at 21:29

Sitecore ICacheInfoมีการเปลี่ยนแปลงการดำเนินการ อย่างไรก็ตามคุณยังสามารถใช้วิธีการRemoveKeysContainingบนแคชได้เมื่อคุณใช้การแคสต์ Sitecore.Caching.Cache

ICacheInfoมีการใช้งานที่หลากหลายและชั้นCacheเป็นหนึ่งในการดำเนินการ

โปรดดูข้อมูลโค้ดด้านล่าง:

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;
        }
    }
}  

โปรดสังเกตว่าแคชมาจากเนมสเปซSitecore.Caching.CacheจากแอสเซมบลีSitecore.Kernel.dll