Copied to clipboard

Flag this post as spam?

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


  • Paul de Quant 403 posts 1521 karma points
    Nov 11, 2020 @ 14:46
    Paul de Quant
    0

    Umbraco 8 Runtime Cache and how to use it

    Hello,

    Can anyone explain how I can use the Umbraco 8 Runtime cache. I would like to know how I can store an item in the runtime cache and retrieve it.

    I've looked on the Umbraco docs but it only shows Umbraco 7, the internet seems to be sparse on information as well.

    Any help (and code examples) will be greatly appreciated.

    Thanks

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Nov 12, 2020 @ 09:26
    David Brendel
    102

    Hi Paul,

    to use the RuntimeCache in v8 you can use the IAppPolicyCache interface and inject that in your classes.

    Hope that helps to get you starting. :)

  • Paul de Quant 403 posts 1521 karma points
    Nov 12, 2020 @ 09:35
    Paul de Quant
    0

    Thanks David, exactly what I needed.

    Cheers

  • Gurumurthy 56 posts 129 karma points
    Sep 05, 2023 @ 21:09
    Gurumurthy
    0

    Hello,

    Is this Runtime cache is at browser level or at server level ?

    Example, I need to cache some api responses locally specific to user and can be used when ever required. I dont want to go with cookies as this will be displayed on browser.

    Any suggestions would be highly appreciated!

    Thanks, Gurumurthy JV

  • Richard Ockerby 39 posts 214 karma points MVP 4x c-trib
    Jan 05, 2025 @ 00:38
    Richard Ockerby
    0

    This is server level cache.

    Building on from David's answer, I was receiving errors about IAppPolicyCache not being available at runtime (v8). Here's how I needed to implement it:

    using Umbraco.Core.Cache;
    
    public class SomeService
    {
        private readonly IAppPolicyCache _cache;
        public SomeService(AppCaches cache) {
            _cache = cache.RuntimeCache;
        }
    
        public SomeObject GetItem() {
            return _cache.GetCacheItem<SomeObject>("A_KEY");
        }
    
        public void SetItem(SomeObject obj) {
            _cache.InsertCacheItem<SomeObject>("A_KEY", () => { return obj; }, new TimeSpan(10,0,0,0), true);
        }
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies