Class CacheRepository<TAuthenticationToken>
Uses System.Runtime.Caching.MemoryCache.Default to provide a caching mechanism to improve performance of a IAggregateRepository<TAuthenticationToken>.
Inheritance
Inherited Members
Namespace: Cqrs.Cache
Assembly: Cqrs.dll
Syntax
public class CacheRepository<TAuthenticationToken> : IAggregateRepository<TAuthenticationToken>
Type Parameters
Name | Description |
---|---|
TAuthenticationToken | The System.Type of authentication token. |
Constructors
CacheRepository(IAggregateRepository<TAuthenticationToken>, IEventStore<TAuthenticationToken>)
Instantiates a new instance of CacheRepository<TAuthenticationToken>.
Declaration
public CacheRepository(IAggregateRepository<TAuthenticationToken> repository, IEventStore<TAuthenticationToken> eventStore)
Parameters
Type | Name | Description |
---|---|---|
IAggregateRepository<TAuthenticationToken> | repository | |
IEventStore<TAuthenticationToken> | eventStore |
Methods
Get<TAggregateRoot>(Guid, IList<IEvent<TAuthenticationToken>>)
Locks the cache, checks if the aggregate is tracked in the Cqrs.Cache.CacheRepository`1.Cache, if it is
retrieves the aggregate from the Cqrs.Cache.CacheRepository`1.Cache and then uses either the provided events
or makes a call Get(Type, Guid, Boolean, Int32) on the Cqrs.Cache.CacheRepository`1.EventStore
and rehydrates the cached aggregate with any new events from it's cached version.
If the aggregate is not in the Cqrs.Cache.CacheRepository`1.Cache
Get<TAggregateRoot>(Guid, IList<IEvent<TAuthenticationToken>>) is called on the Cqrs.Cache.CacheRepository`1.Repository.
Declaration
public virtual TAggregateRoot Get<TAggregateRoot>(Guid aggregateId, IList<IEvent<TAuthenticationToken>> events = null)where TAggregateRoot : IAggregateRoot<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
System.Guid | aggregateId | The ID of the IAggregateRoot<TAuthenticationToken> to get. |
System.Collections.Generic.IList<IEvent<TAuthenticationToken>> | events | A collection of IEvent<TAuthenticationToken> to replay on the retrieved IAggregateRoot<TAuthenticationToken>. If null, the IEventStore<TAuthenticationToken> will be used to retrieve a list of IEvent<TAuthenticationToken> for you. |
Returns
Type | Description |
---|---|
TAggregateRoot |
Type Parameters
Name | Description |
---|---|
TAggregateRoot | The System.Type of the IAggregateRoot<TAuthenticationToken>. |
Implements
Save<TAggregateRoot>(TAggregateRoot, Nullable<Int32>)
Locks the cache, adds the provided aggregate
to the cache if not already in it, then calls Save<TAggregateRoot>(TAggregateRoot, Nullable<Int32>) on Cqrs.Cache.CacheRepository`1.Repository.
In the event of an System.Exception the aggregate
is always ejected out of the Cqrs.Cache.CacheRepository`1.Cache.
Declaration
public virtual void Save<TAggregateRoot>(TAggregateRoot aggregate, int ? expectedVersion = null)where TAggregateRoot : IAggregateRoot<TAuthenticationToken>
Parameters
Type | Name | Description |
---|---|---|
TAggregateRoot | aggregate | The IAggregateRoot<TAuthenticationToken> to save and persist. |
System.Nullable<System.Int32> | expectedVersion | The version number the IAggregateRoot<TAuthenticationToken> is expected to be at. |
Type Parameters
Name | Description |
---|---|
TAggregateRoot | The System.Type of the IAggregateRoot<TAuthenticationToken>. |