Table of Contents

Class SlimMemoryCacheOptions

Namespace
Cuemon.Runtime.Caching
Assembly
Cuemon.Runtime.Caching.dll

Configuration options for SlimMemoryCache.

public class SlimMemoryCacheOptions : IValidatableParameterObject, IParameterObject
Inheritance
SlimMemoryCacheOptions
Implements

Examples

The following example demonstrates how to configure for sweep intervals and cache-key generation.

using System;
using Cuemon.Runtime.Caching;

namespace MyApp.Examples;

public static class SlimMemoryCacheOptionsExample
{
    public static void Demonstrate()
    {
        var options = new SlimMemoryCacheOptions
        {
            EnableCleanup = false,
            FirstSweep = TimeSpan.FromSeconds(10),
            SucceedingSweep = TimeSpan.FromSeconds(30),
            KeyProvider = (key, ns) => key.Length + (ns == CacheEntry.NoScope ? 0 : ns.Length)
        };

        options.ValidateOptions();

        Console.WriteLine(options.EnableCleanup);
        Console.WriteLine(options.FirstSweep);
        Console.WriteLine(options.KeyProvider("session", "docs"));
    }
}

Constructors

SlimMemoryCacheOptions()

Initializes a new instance of the SlimMemoryCacheOptions class.

public SlimMemoryCacheOptions()

Remarks

The following table shows the initial property values for an instance of SlimMemoryCacheOptions.

PropertyInitial Value
EnableCleanuptrue
FirstSweepAfter 30 seconds
SucceedingSweepEvery 2 minutes
KeyProvider(key, ns) => Generate.HashCode64(ns == Cache.NoScope ? key.ToUpperInvariant() : $"{key}^{nameof(SlimMemoryCache)}^{ns}".ToUpperInvariant());

Properties

EnableCleanup

Gets or sets a value indicating whether a periodic sweep clean-up is done on the cache.

public bool EnableCleanup { get; set; }

Property Value

bool

true if a periodic sweep clean-up is done on the cache; otherwise, false.

FirstSweep

Gets or sets the TimeSpan that specifies the amount of time to wait before the initial first sweep clean-up.

public TimeSpan FirstSweep { get; set; }

Property Value

TimeSpan

The TimeSpan that specifies the amount of time to wait before the initial first sweep clean-up.

KeyProvider

Gets or sets the function delegate that is responsible for providing a unique identifier for a cache entry.

public Func<string, string, long> KeyProvider { get; set; }

Property Value

Func<string, string, long>

The function delegate that is responsible for providing a unique identifier for a cache entry.

SucceedingSweep

Gets or sets the TimeSpan that specifies the interval for every succeeding sweep clean-up after the initial FirstSweep.

public TimeSpan SucceedingSweep { get; set; }

Property Value

TimeSpan

The TimeSpan that specifies the interval for every succeeding sweep clean-up.

Methods

ValidateOptions()

Determines whether the public read-write properties of this instance are in a valid state.

public void ValidateOptions()

Remarks

This method is expected to throw exceptions when one or more conditions fails to be in a valid state.

Exceptions

InvalidOperationException

KeyProvider cannot be null.