Show / Hide Table of Contents

Class StateBase<TKey, TValue>

An abstract base class implementing IState<TKey, TValue> with a method to query and retrieve an object.

Inheritance
object
StateBase<TKey, TValue>
GameStateBase
State<TKey, TValue>
Implements
IState<TKey, TValue>
IReadOnlyCollection<TValue>
IEnumerable<TValue>
IEnumerable
IHasUpdateTime
IDisposable
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
Assembly: GameStateTracker.Core.dll
Syntax
public abstract class StateBase<TKey, TValue> : IState<TKey, TValue>, IReadOnlyCollection<TValue>, IEnumerable<TValue>, IEnumerable, IHasUpdateTime, IDisposable where TValue : class
Type Parameters
Name Description
TKey

The key type to query for an object.

TValue

The object type.

Constructors

View Source

StateBase(IObjectCache<TKey, TValue>, ILogger<StateBase<TKey, TValue>>?)

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

Declaration
protected StateBase(IObjectCache<TKey, TValue> cache, ILogger<StateBase<TKey, TValue>>? logger = null)
Parameters
Type Name Description
IObjectCache<TKey, TValue> cache

The cache to use to store objects.

ILogger<StateBase<TKey, TValue>> logger

The logger to use.

Properties

View Source

Cache

Gets the cache of objects.

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

Count

Gets the count of objects in the cache.

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

IsUpdateInProgress

Gets a value indicating whether or not the state is being updated.

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

Logger

Gets or sets the logger to use.

Declaration
public ILogger<StateBase<TKey, TValue>> Logger { get; set; }
Property Value
Type Description
ILogger<StateBase<TKey, TValue>>
View Source

Semaphore

Gets a semaphore to prevent concurrent attempts at retrieving objects and updating the cache.

Declaration
protected SemaphoreSlim Semaphore { get; }
Property Value
Type Description
SemaphoreSlim
View Source

UpdateProcessor

Gets a task queue for delaying state updates.

Declaration
protected TaskQueue UpdateProcessor { get; }
Property Value
Type Description
TaskQueue
View Source

UpdateTime

Gets or sets the current time to compare to when querying the cache.

Declaration
public DateTime? UpdateTime { get; set; }
Property Value
Type Description
DateTime?

Methods

View Source

AgeObject(TKey)

Gets the age of an object in the cache.

Declaration
protected virtual TimeSpan? AgeObject(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

Clear(TKey)

Removes an object from the cache.

Declaration
public bool Clear(TKey info)
Parameters
Type Name Description
TKey info

The object info.

Returns
Type Description
bool

True if the object was removed.

View Source

Dispose()

Dispose the state.

Declaration
public void Dispose()
View Source

Existing(TKey)

Gets a cached object with the given info.

Declaration
public virtual TValue? Existing(TKey info)
Parameters
Type Name Description
TKey info

The object info.

Returns
Type Description
TValue

The object.

View Source

Get(TKey, TimeSpan, CancellationToken)

Retrieves an object.

Declaration
public virtual Task<TValue?> Get(TKey query, TimeSpan maxAge, CancellationToken token = default)
Parameters
Type Name Description
TKey query

The object to look for.

TimeSpan maxAge

The maximum age of the object, if it exists in the cache.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<TValue>

The object.

View Source

GetEnumerator()

Returns an IEnumerator<T> for objects in the cache.

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

An IEnumerator<T> object.

View Source

GetObject(TKey, CancellationToken)

Retrieves an object matching the given query.

Declaration
protected abstract Task<TValue?> GetObject(TKey query, CancellationToken token)
Parameters
Type Name Description
TKey query

The objects to look for.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<TValue>

An object.

View Source

Set(in TKey, TValue?)

Stores an object and set its age in the cache.

Declaration
protected virtual void Set(in TKey info, TValue? value)
Parameters
Type Name Description
TKey info

The object information.

TValue value

The object to store. If null, the object is removed, but the cache keeps the object's age.

View Source

WaitForUpdateFinished()

Waits for the state to finish being updated.

Declaration
public Task WaitForUpdateFinished()
Returns
Type Description
Task

A task that completes when the state is no longer being updated.

Implements

IState<TKey, TValue>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
IHasUpdateTime
IDisposable

Extension Methods

IEnumerableExtensions.WithoutLast<T>(IEnumerable<T>)
  • View Source
In this article
Back to top Generated by DocFX