Copied to clipboard

Flag this post as spam?

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


  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Nov 07, 2024 @ 17:57
    Alex Skrypnyk
    0

    Refresh Umbraco Memory Cache from code in v10

    Maybe somebody has a code example of how to refresh Memory Cache from code instead of doing it manually in the Settings section.

    Alex

  • Afreed 86 posts 383 karma points
    Nov 08, 2024 @ 07:19
    Afreed
    100

    Hi Alex,

    You can refresh the Umbraco memory cache programmatically by using the DistributedCache service. Here’s a simple example:

    using Umbraco.Cms.Core.Cache;
    public class CacheHelper{
        private readonly DistributedCache _distributedCache;
        public CacheHelper(DistributedCache distributedCache)
        {
            _distributedCache = distributedCache;
        }
        // Method to refresh all published snapshots in the distributed cache, effectively refreshing the memory cache.
        public void RefreshMemoryCache()
        {
            _distributedCache.RefreshAllPublishedSnapshot();
        }}
    

    Hope this is what you are looking for.

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Nov 08, 2024 @ 12:03
    Alex Skrypnyk
    0

    Hi Afreed

    Thank you so much, let me test

  • 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