Show / Hide Table of Contents

Class ObjectCacheBase<TKey, TValue>

An abstract base class for implementing IObjectCache<TKey, TValue>.

Inheritance
object
ObjectCacheBase<TKey, TValue>
ClassObjectCacheBase<TKey, TValue>
SimpleCache<T>
SimpleCache<TKey, TValue>
Implements
IObjectCache<TKey, TValue>
ICollection<TValue>
IEnumerable<TValue>
IDictionary<TKey, TValue>
ICollection<KeyValuePair<TKey, TValue>>
IEnumerable<KeyValuePair<TKey, TValue>>
IEnumerable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Microsoft.XboxStudios.GameStateTracker.Cache
Assembly: GameStateTracker.Core.dll
Syntax
public abstract class ObjectCacheBase<TKey, TValue> : IObjectCache<TKey, TValue>, ICollection<TValue>, IEnumerable<TValue>, IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable where TKey : IEquatable<TKey> where TValue : notnull
Type Parameters
Name Description
TKey

The info type.

TValue

The object type.

Constructors

View Source

ObjectCacheBase(IReadOnlyCollection<TValue>?)

Initializes a new instance of the ObjectCacheBase<TKey, TValue> class.

Declaration
protected ObjectCacheBase(IReadOnlyCollection<TValue>? existing = null)
Parameters
Type Name Description
IReadOnlyCollection<TValue> existing

The objects to initialize the cache with.

Properties

View Source

Ages

Gets a mapping from object info to age in the cache.

Declaration
protected TimeElapsedHelper<TKey> Ages { get; }
Property Value
Type Description
TimeElapsedHelper<TKey>
View Source

Count

Gets the number of elements contained in the cache.

Declaration
public int Count { get; }
Property Value
Type Description
int
View Source

IsReadOnly

Gets a value indicating whether the cache is read-only.

Declaration
public bool IsReadOnly { get; }
Property Value
Type Description
bool
View Source

this[TKey]

Gets an object from the cache matching the given info.

Declaration
public TValue this[TKey info] { get; set; }
Parameters
Type Name Description
TKey info

The object info.

Property Value
Type Description
TValue

The object, or null if no object was found.

View Source

Keys

Gets a collections of the object keys in this cache.

Declaration
public ICollection<TKey> Keys { get; }
Property Value
Type Description
ICollection<TKey>
View Source

Objects

Gets a mapping from object info to cached object.

Declaration
protected IDictionary<TKey, TValue> Objects { get; }
Property Value
Type Description
IDictionary<TKey, TValue>
View Source

Values

Gets a collections of the objects in this cache.

Declaration
public ICollection<TValue> Values { get; }
Property Value
Type Description
ICollection<TValue>

Methods

View Source

Add(KeyValuePair<TKey, TValue>)

Adds an object to the cache with the provided key.

Declaration
public void Add(KeyValuePair<TKey, TValue> item)
Parameters
Type Name Description
KeyValuePair<TKey, TValue> item

The object key-value pair.

View Source

Add(TKey, TValue)

Adds an object to the cache with the provided key.

Declaration
public void Add(TKey key, TValue value)
Parameters
Type Name Description
TKey key

The key.

TValue value

The object.

View Source

Add(TValue)

Adds an object to the cache.

Declaration
public void Add(TValue item)
Parameters
Type Name Description
TValue item

The object.

View Source

Clear()

Removes all objects from the cache.

Declaration
public void Clear()
View Source

Contains(KeyValuePair<TKey, TValue>)

Determines whether the cache contains the specified object key-value pair.

Declaration
public bool Contains(KeyValuePair<TKey, TValue> item)
Parameters
Type Name Description
KeyValuePair<TKey, TValue> item

The object key-value pair.

Returns
Type Description
bool

True if the cache contains the specified object key-value pair.

View Source

Contains(TValue)

Determines whether the cache contains the specified object.

Declaration
public bool Contains(TValue item)
Parameters
Type Name Description
TValue item

The object.

Returns
Type Description
bool

True if the cache contains the specified object.

View Source

ContainsKey(TKey)

Determines whether the cache contains an object with the specified key.

Declaration
public bool ContainsKey(TKey key)
Parameters
Type Name Description
TKey key

The key.

Returns
Type Description
bool

True if the cache contains an object with the specified key.

View Source

CopyTo(KeyValuePair<TKey, TValue>[], int)

Copies the object key-value pairs in the cache to an array, starting at a particular array index.

Declaration
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
Parameters
Type Name Description
KeyValuePair<TKey, TValue>[] array

The array to copy to.

int arrayIndex

The zero-based index in array at which copying begins.

View Source

CopyTo(TValue[], int)

Copies the objects in the cache to an array, starting at a particular array index.

Declaration
public void CopyTo(TValue[] array, int arrayIndex)
Parameters
Type Name Description
TValue[] array

The array to copy to.

int arrayIndex

The zero-based index in array at which copying begins.

View Source

GetEnumerator()

Returns an IEnumerator<T> object for the cache.

Declaration
public IEnumerator<TValue> GetEnumerator()
Returns
Type Description
IEnumerator<TValue>

An IEnumerator<T> object for the cache.

View Source

GetKey(TValue)

Gets the info describing an object.

Declaration
protected abstract TKey GetKey(TValue input)
Parameters
Type Name Description
TValue input

The object.

Returns
Type Description
TKey

The object info.

View Source

GetObjectAge(TKey)

Gets the age of an object in the cache.

Declaration
public TimeSpan? GetObjectAge(TKey info)
Parameters
Type Name Description
TKey info

The object info.

Returns
Type Description
TimeSpan?

The time since the object was last refreshed.

View Source

GetObjectAge(TKey, DateTime)

Gets the age of an object in the cache.

Declaration
public virtual TimeSpan? GetObjectAge(TKey info, DateTime now)
Parameters
Type Name Description
TKey info

The object info.

DateTime now

The current time to compare to.

Returns
Type Description
TimeSpan?

The time since the object was last refreshed.

View Source

RefreshObject(TKey)

Updates the age of an object in the cache.

Declaration
public void RefreshObject(TKey info)
Parameters
Type Name Description
TKey info

The object info.

View Source

RefreshObject(TKey, DateTime)

Updates the age of an object in the cache.

Declaration
public void RefreshObject(TKey info, DateTime now)
Parameters
Type Name Description
TKey info

The object info.

DateTime now

The current time to set.

View Source

Remove(KeyValuePair<TKey, TValue>)

Removes the specified object key-value pair from the cache.

Declaration
public bool Remove(KeyValuePair<TKey, TValue> item)
Parameters
Type Name Description
KeyValuePair<TKey, TValue> item

The object key-value pair.

Returns
Type Description
bool

True if the object key-value pair was removed.

View Source

Remove(TKey)

Removes the object with the specified key from the cache.

Declaration
public virtual bool Remove(TKey item)
Parameters
Type Name Description
TKey item

The key.

Returns
Type Description
bool

True if the object was removed.

View Source

Remove(TValue)

Removes the specified object from the cache.

Declaration
public bool Remove(TValue item)
Parameters
Type Name Description
TValue item

The object.

Returns
Type Description
bool

True if the object was removed.

View Source

TryGetValue(TKey, out TValue)

Attempts to get the object associated with the specified key from the cache.

Declaration
public bool TryGetValue(TKey key, out TValue value)
Parameters
Type Name Description
TKey key

The key.

TValue value

When this method returns, value contains the object.

Returns
Type Description
bool

True if the an object was found.

Implements

IObjectCache<TKey, TValue>
ICollection<T>
IEnumerable<T>
IDictionary<TKey, TValue>
ICollection<T>
IEnumerable<T>
IEnumerable
  • View Source
In this article
Back to top Generated by DocFX