Table of Contents

CacheEntry Class

Definition

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

Represents an individual cache entry in the cache.

public class CacheEntry
Inheritance
CacheEntry

Examples

The following example demonstrates how to register a cache entry with invalidation rules and inspect its expiration behavior.

using System;
using Cuemon.Runtime.Caching;

namespace MyApp.Examples;

public static class CacheEntryExample
{
    public static void Demonstrate()
    {
        var cache = new SlimMemoryCache();
        var entry = new CacheEntry("session", "cached-value", "docs");

        cache.Add(entry, new CacheInvalidation(TimeSpan.FromSeconds(30)));

        Console.WriteLine(entry.CanExpire);
        Console.WriteLine(entry.HasExpired(entry.Accessed.AddSeconds(31)));
        Console.WriteLine(entry.ToString().Contains("Key=session"));
    }
}

Constructors

Name Description
CacheEntry(string, object, string)

Initializes a new instance of the CacheEntry class.

Fields

Name Description
NoScope

Represents a cache with a global scope, eg. no namespace.

Properties

Name Description
Accessed

Gets the UTC date time value from when this CacheEntry was last accessed.

CanExpire

Gets a value indicating whether this CacheEntry can expire.

Inserted

Gets the UTC date time value from when this CacheEntry was inserted.

Invalidation

Gets the cache invalidation of this CacheEntry.

Key

Gets the unique identifier of this CacheEntry.

Namespace

Gets the optional namespace that provides a scope to this CacheEntry.

Value

Gets the stored value of this CacheEntry.

Methods

Name Description
HasExpired(DateTime)

Determines whether the specified time resolves this CacheEntry as expired.

OnExpiredRaised(CacheEntryEventArgs)

Raises the Expired event.

ToString()

Returns a string that represents this instance.

Events

Name Description
Expired

Occurs when a CacheEntry object with an associated Dependency has expired.