Table of Contents

CachingManager Class

Definition

Namespace
Cuemon.Runtime.Caching
Assemblies
Cuemon.Runtime.Caching.dll
Source
src/Cuemon.Runtime.Caching/CachingManager.cs

Provides access to caching in an application.

public static class CachingManager
Inheritance
CachingManager

Examples

The following example demonstrates how to get or add a cached value using CachingManager.Cache. It checks for an existing key, adds a value with a 5-minute expiration if not found, and verifies the cached instance is reused on subsequent accesses.

using System;
using Cuemon.Runtime.Caching;

namespace Cuemon.Runtime.Caching;

public class CachingManagerExample
{
    public void Demonstrate()
    {
        var cache = CachingManager.Cache;
        var key = "myKey";
        var value = cache.Get(key);
        if (value == null)
        {
            cache.Add(key, DateTime.UtcNow, TimeSpan.FromMinutes(5));
        }
        value = cache.Get(key);
        Console.WriteLine($"Cached value: {value}");

        var sameValue = cache.Get(key);
        Console.WriteLine($"Same instance? {value == sameValue}");
    }
}

Properties

Name Description
Cache

Gets a singleton instance of SlimMemoryCache that is an in-memory cache for an application.