ObjectCache<T> Class

A simple object recycling system.

public abstract class ObjectCache<T> where T : class

Type parameters

T
Type of the object to cache

Constructors

NameDescription
ObjectCache()Initializes a new instance of the ObjectCache<T> class.

ObjectCache()

ObjectCache.cs

Initializes a new instance of the ObjectCache<T> class.

protected ObjectCache()

Methods

NameDescription
Clear()Clears this cache.
Get()Gets a new instance.
NewInstance()Creates a new instance of {T}
Release(T)Releases the specified instance.
Reset(T)Resets the specified instance when ObjectCache<T>.Release is called before storing back to this cache.

Clears this cache.

public void Clear()

Gets a new instance.

public T Get()

Returns

T

NewInstance()

Creates a new instance of {T}

protected abstract T NewInstance()

Returns

T A new instance of {T}

Release(T)

ObjectCache.cs

Releases the specified instance.

public void Release(T instance)

Parameters

instance T
The instance.

Exceptions

ArgumentNullException
if instance is null

Reset(T)

Resets the specified instance when ObjectCache<T>.Release is called before storing back to this cache.

protected abstract void Reset(T instance)

Parameters

instance T
The instance.