Show / Hide Table of Contents

Class InternCache

Provides extension methods to create intern caches to reuse values.

Inheritance
System.Object
InternCache
Namespace: System.Memory
Assembly: Nuqleon.Memory.dll
Syntax
public static class InternCache : Object

Methods

CreateInternCache<T>(IMemoizationCacheFactory)

Creates a new intern cache for values of type T.

Declaration
public static IInternCache<T> CreateInternCache<T>(this IMemoizationCacheFactory cacheFactory)
    where T : class
Parameters
Type Name Description
IMemoizationCacheFactory cacheFactory

The cache factory used to create an intern cache.

Returns
Type Description
IInternCache<T>

Empty intern cache for values of type T.

Type Parameters
Name Description
T

The type of the values to intern.

CreateWeakInternCache<T>(IMemoizationCacheFactory, Func<T, T>)

Creates a new intern cache for values of type T that supports trimming entries.

Declaration
public static IWeakInternCache<T> CreateWeakInternCache<T>(this IMemoizationCacheFactory cacheFactory, Func<T, T> clone)
    where T : class
Parameters
Type Name Description
IMemoizationCacheFactory cacheFactory

The cache factory used to create an intern cache.

System.Func<T, T> clone

Function to clone values in order to maintain intern cache entries. See remarks for more information.

Returns
Type Description
IWeakInternCache<T>

Empty intern cache for values of type T.

Type Parameters
Name Description
T

The type of the values to intern.

Remarks

Intern caches perform an equality based lookup to locate an existing interned copy of the provided value in an internal dictionary. After looking up an interned value, the caller can discard the original value it provided to the Intern method. The interned value is kept in the intern cache using a weak reference, so it can be trimmed from the cache if no more strong references are held to it. In order to prevent the intern cache's dictionary from keeping the weak references alive, the keys in the dictionary are created using the specified clone function. This causes the reference held in the value to be different from the one in the key, which is only used for equality checks. A trim operation locates weak references in the value slots with a dangling reference and removes the cache entry from the dictionary.

In This Article
Back to top Generated by DocFX