Copied to clipboard

Flag this post as spam?

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


  • Genc Kastrati 86 posts 401 karma points
    Mar 10, 2017 @ 10:17
    Genc Kastrati
    0

    List cached items in the RuntimeCache

    Hello everyone,

    I can't seem to find a way to list what has been cached in the RuntimeCache.

    Is there a way to see what has been insterted into the cache, from statements like these but without knowing the full key name?

    cache.InsertCacheItem("CacheName_SomethingSomething", () => contentItems, timeout: TimeSpan.FromMinutes(10));

    Thank you! Genc

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 10, 2017 @ 12:44
    Dave Woestenborghs
    0

    Hi Genc,

    This is explained in the documentation here : https://our.umbraco.org/documentation/Reference/Cache/updating-cache

    Read the part about adding and retreiving. You can use the same call for adding and retreiving.

    Dave

  • Genc Kastrati 86 posts 401 karma points
    Mar 10, 2017 @ 12:54
    Genc Kastrati
    0

    Hi Date, thank you!

    The way I've understood this is that I need to know the key (in this case ""MyCacheKey"). But what if I want to get a list of whatever is cached, without knowing the key name? There seems to be no "GetCacheItems()" is there?

    Thank you, Genc

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Mar 10, 2017 @ 13:21
    Dave Woestenborghs
    101

    Hi Genc,

    This is not possible using the Umbraco API.

    But you can do something like this :

    IDictionaryEnumerator enumerator = System.Web.HttpRuntime.Cache.GetEnumerator();
    while (enumerator.MoveNext())
    {
        string key = (string)enumerator.Key;
        object value = enumerator.Value;
        ...
    }
    

    And that would list them all.

    Dave

  • Genc Kastrati 86 posts 401 karma points
    Mar 10, 2017 @ 18:29
    Genc Kastrati
    0

    Thank you Dave, didn't realize Umbraco was using "System.Web.HttpRuntime.Cache". Might have missed that bit.

    Thank you for your help! Genc

Please Sign in or register to post replies

Write your reply to:

Draft