Version 2.1.0.0

Cache<T> class

Namespace: Sirenix.Utilities
Assembly: Sirenix.Utilities
public sealed class Cache<T> : ICache<T>, 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.Utilities.ICacheNotificationReceiver interface will receive notifications when they are claimed and freed.

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

Type Parameters

T

The type which is cached.

Properties

MaxCacheSize
Gets or sets the maximum size of the cache. This value can never go beneath 1.
public static int MaxCacheSize { get; set; }
Value
Gets the cached value.
public T Value { get; }
Exceptions
System.InvalidOperationException

Cannot access a cache while it is freed.

Methods

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

A cached value of type .

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.