Class ObjectCacheBase<TKey, TValue>
An abstract base class for implementing IObjectCache<TKey, TValue>.
Inheritance
Implements
Inherited Members
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 SourceObjectCacheBase(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 SourceAges
Gets a mapping from object info to age in the cache.
Declaration
protected TimeElapsedHelper<TKey> Ages { get; }
Property Value
Type | Description |
---|---|
TimeElapsedHelper<TKey> |
Count
Gets the number of elements contained in the cache.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
IsReadOnly
Gets a value indicating whether the cache is read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
bool |
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. |
Keys
Gets a collections of the object keys in this cache.
Declaration
public ICollection<TKey> Keys { get; }
Property Value
Type | Description |
---|---|
ICollection<TKey> |
Objects
Gets a mapping from object info to cached object.
Declaration
protected IDictionary<TKey, TValue> Objects { get; }
Property Value
Type | Description |
---|---|
IDictionary<TKey, TValue> |
Values
Gets a collections of the objects in this cache.
Declaration
public ICollection<TValue> Values { get; }
Property Value
Type | Description |
---|---|
ICollection<TValue> |
Methods
View SourceAdd(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. |
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. |
Add(TValue)
Adds an object to the cache.
Declaration
public void Add(TValue item)
Parameters
Type | Name | Description |
---|---|---|
TValue | item | The object. |
Clear()
Removes all objects from the cache.
Declaration
public void Clear()
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. |
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. |
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. |
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 |
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 |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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, |
Returns
Type | Description |
---|---|
bool | True if the an object was found. |