Agility Dependency Cache


The Agility Dependency Cache is designed to help developers manage content caching in conjunction with Agility content. This means you can cache whatever you'd like and set a dependency on specific Agility content. When the Agility content has been updated, then your cache will expire automatically and you can re-hydrate your cache.

An additional feature of the AgilityDependencyCache is that the content will be cached in the HttpContext.Cache only if the website is in “Live” mode. If the website is in development or preview mode the content will be cached in the HttpContent.Items.

The code snippet below illustrates how you can wrap a data-access call in an AgilityDependency Cache so that your content is cached while the associated Agility content is cached, and when the Agility content is updated, so will your custom cache key.

public DataView GetData()
    // Check the cache to see if we already have an item added
    string cacheKey = "some string"
    object someData = Agility.Web.Utils.AgilityDependencyCache.Select(cacheKey);  
    if (someData == null)
        // Nothing found in the cache
        someData = GetSomeData(); //the content you want to cache
        // Add the data into the cache ready for next time we want to access it and base it on an Agility content list (by reference name)
        Agility.Web.Utils.AgilityDependencyCache.Insert(cacheKey, someData , new List { "SomeAgilityContentReferenceName"}, DateTime.Now.AddHours(1));
    return someData;
1 out of 1 found this helpful



Please sign in to leave a comment.