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 4 posts 79 karma points
    Jan 03, 2020 @ 10:51
    Liam Prowse
    0

    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
        {
            get
            {
                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: https://our.umbraco.com/documentation/Reference/Cache/examples/tags 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 2141 posts 14344 karma points MVP 8x c-trib
    Jan 11, 2020 @ 08:35
    Marc Goodson
    0

    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....

    https://github.com/umbraco/Umbraco-CMS/blob/0b6f1f6e117d1cb475230073699c725ea7b2dd4a/src/Umbraco.Web/Mvc/UmbracoViewPageOfTModel.cs

    So you should be able to use

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

    regards

    Marc

  • Jon 92 posts 166 karma points
    Feb 21, 2022 @ 16:08
    Jon
    0

    What happens on a Load Balance environment - when the front end URL is different to the Backoffice CMS URL - how can we clear the cache in the CMS and for it to effect the Front end?

Please Sign in or register to post replies

Write your reply to:

Draft