Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Liam Prowse 1 post 71 karma points
    Jan 03, 2020 @ 10:51
    Liam Prowse

    Hey, I've been trying to replicate this caching from one of our v7 sites in a new Umbraco 8 site, however lots has changed and I cant seem to figure it out.

     public IList<HelpTopic> HelpTopics
                return (IList<HelpTopic>)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(HelpTopicsCacheKey, () =>
                    var umbraco = new UmbracoHelper(UmbracoContext.Current);
                    var contentAtRoot = umbraco.TypedContentAtRoot();
                    var container = contentAtRoot.FirstOrDefault(x => x.DocumentTypeAlias == "helpSectionContainer");
                    var helpTopicContainer = container.Children.FirstOrDefault(x => x.DocumentTypeAlias == "helpTopicContainer") as HelpTopicContainer;
                    var helpTopics = helpTopicContainer.Children<HelpTopic>();
                    return helpTopics.ToList();

    I am aware that the way that content is fetched there will not work in V8, and that's okay, its this part that's giving me the trouble:

    return (IList<HelpTopic>)ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(HelpTopicsCacheKey, () =>

    I have tried looking at the example here: however it doesn't seem to help.

    I need to be able to call this from a template file.

    Any help is appreciated, thank you in advance :)

  • Marc Goodson 1203 posts 8073 karma points MVP 5x c-trib
    Jan 11, 2020 @ 08:35
    Marc Goodson

    Hi Liam

    In V8 the application caches: RuntimeCache, RequestCache and IsolatedCache are represented by an AppCaches 'gateway' class.

    The example you refer to in the documentation is injecting this AppCaches class into the custom service.

    How do you access AppCaches from a template view?

    Well it's a property of the UmbracoViewPage<T> class, so as your View/Template inherits UmbracoViewPage you have access to an AppCaches property... (in the same way that you can access Services. to access the core services, or Umbraco. to access the Umbraco Helper methods....

    So you should be able to use

    IList<HelpTopic>)AppCaches.RuntimeCache.GetCacheItem(HelpTopicsCacheKey, () =>



Please Sign in or register to post replies

Write your reply to: