Version 3.0.0.2

Cache<T> class

Namespace: Sirenix.Serialization.Utilities
Assembly: Sirenix.Serialization
public sealed class Cache<T> : ICache, IDisposable where T : class, new()
Provides an easy way of claiming and freeing cached values of any non-abstract reference type with a public parameterless constructor.

Cached types which implement the Sirenix.Serialization.Utilities.ICacheNotificationReceiver interface will receive notifications when they are claimed and freed.

Only one thread should be holding a given cache instance at a time if Sirenix.Serialization.Utilities.ICacheNotificationReceiver is implemented, since the invocation of Sirenix.Serialization.Utilities.ICacheNotificationReceiver.OnFreed is not thread safe, IE, weird stuff might happen if multiple different threads are trying to free the same cache instance at the same time. This will practically never happen unless you're doing really strange stuff, but the case is documented here.

Inheritance
  • System.Object
  • Cache<T>
See Also
  • System.IDisposable

Type Parameters

T

The type which is cached.

Fields

Value
The cached value.
public T Value

Properties

IsFree
Gets a value indicating whether this cached value is free.
public bool IsFree { get; }
MaxCacheSize
Gets or sets the maximum size of the cache. This value can never go beneath 1.
public static int MaxCacheSize { get; set; }

Methods

Claim()
Claims a cached value of type .
public static Cache<T> Claim()
Returns
Cache<T>

A cached value of type .

Release()
Releases this cached value.
public void Release()
Release(Cache<T>)
Releases a cached value.
public static void Release(Cache<T> cache)
Parameters
Cache<T> cache

The cached value to release.

Exceptions
System.ArgumentNullException

The cached value to release is null.

Operators

Implicit(Cache<T> to T)
Performs an implicit conversion from Cache<T> to .
public static implicit operator T(Cache<T> cache)
Parameters
Cache<T> cache

The cache to convert.

Returns
T

The result of the conversion.