Class CacheLinksDecorator<TLinkAddress>
- Namespace
- Foundation.Data.Doublets.Cli
- Assembly
- Foundation.Data.Doublets.Cli.dll
A links store used as a cache: links can expire, and the store can be kept to
a number of links by evicting the ones used least recently. It has the API of
any other store, so only a store that selects it pays for it. See
docs/ENGINE-CACHE.md. The Rust twin is link_cli::CacheLinks, the
JavaScript one CacheLinks of @link-foundation/link-cli-client.
public class CacheLinksDecorator<TLinkAddress> : LinksDecoratorBase<TLinkAddress>, INamedTypesLinks<TLinkAddress>, ILinks<TLinkAddress>, ILinks<TLinkAddress, LinksConstants<TLinkAddress>>, INamedTypes<TLinkAddress>, IComposedLinks<TLinkAddress> where TLinkAddress : struct, IUnsignedNumber<TLinkAddress>
Type Parameters
TLinkAddress
- Inheritance
-
LinksOperatorBase<TLinkAddress>LinksDecoratorBase<TLinkAddress>CacheLinksDecorator<TLinkAddress>
- Implements
-
INamedTypesLinks<TLinkAddress>ILinks<TLinkAddress>ILinks<TLinkAddress, LinksConstants<TLinkAddress>>INamedTypes<TLinkAddress>IComposedLinks<TLinkAddress>
- Inherited Members
-
LinksDecoratorBase<TLinkAddress>._constantsLinksDecoratorBase<TLinkAddress>._facadeLinksDecoratorBase<TLinkAddress>.FacadeLinksDecoratorBase<TLinkAddress>.ConstantsLinksOperatorBase<TLinkAddress>._linksLinksOperatorBase<TLinkAddress>.Links
- Extension Methods
Remarks
The two rules differ on purpose. A deadline is a promise, so a link that comes due is deleted with whatever the store's own delete takes with it. Capacity only has to free a place, so it evicts a link nothing else uses and takes nothing else along. When every link is in use the write is refused with InvalidOperationException.
There is no worker. Everything due is deleted by the next call that touches the store, or by PurgeExpired() when a caller wants to run it on a timer. Deadlines live in memory: a store opened again has links without one.
A link is made here in two steps, Create and then Update, and only
the second one says what it refers to. So capacity is kept when the content of
the new link arrives, or by the next write when none does, and the source and
target it names are not evicted for it. Until then the new link is counted
over the limit. A refused link is deleted again.
Constructors
CacheLinksDecorator(INamedTypesLinks<TLinkAddress>, CacheOptions?, Func<ulong>?)
public CacheLinksDecorator(INamedTypesLinks<TLinkAddress> links, CacheOptions? options = null, Func<ulong>? clock = null)
Parameters
linksINamedTypesLinks<TLinkAddress>The store below. Every write has to go through this decorator for it to know which links exist.
optionsCacheOptionsWhat to enforce.
clockFunc<ulong>Milliseconds, the system clock by default. A step back delays what comes due.
Properties
QueryLimits
Optional admission limits for the ordinary query processor.
public QueryLimits? QueryLimits { get; }
Property Value
ReassignsNames
Whether assigning a name removes its previous owner.
public bool ReassignsNames { get; }
Property Value
Methods
CaptureNames()
A detached logical name snapshot for undo. Stores supporting names of absent rows override this default row-based enumeration to include them.
public IReadOnlyDictionary<TLinkAddress, string> CaptureNames()
Returns
- IReadOnlyDictionary<TLinkAddress, string>
Claims(TLinkAddress)
Whether address is of the store below.
public virtual bool Claims(TLinkAddress address)
Parameters
addressTLinkAddress
Returns
Count(IList<TLinkAddress>?)
Counts the restriction.
public override TLinkAddress Count(IList<TLinkAddress>? restriction)
Parameters
restrictionIList<TLinkAddress>The restriction.
Returns
- TLinkAddress
The link
Create(IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)
Creates the restriction.
public override TLinkAddress Create(IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)
Parameters
substitutionIList<TLinkAddress>The restriction.
handlerWriteHandler<TLinkAddress>Optional callback; null continues without invoking a callback.
Returns
- TLinkAddress
The link
Delete(IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)
Deletes the restriction.
public override TLinkAddress Delete(IList<TLinkAddress>? restriction, WriteHandler<TLinkAddress>? handler)
Parameters
restrictionIList<TLinkAddress>The restriction.
handlerWriteHandler<TLinkAddress>Optional callback; null continues without invoking a callback.
Returns
- TLinkAddress
Each(IList<TLinkAddress>?, ReadHandler<TLinkAddress>?)
A read of one link by its address, or by its source and target, uses what it finds; a scan does not.
public override TLinkAddress Each(IList<TLinkAddress>? restriction, ReadHandler<TLinkAddress>? handler)
Parameters
restrictionIList<TLinkAddress>handlerReadHandler<TLinkAddress>
Returns
- TLinkAddress
EnsureCreated(params TLinkAddress[])
Creates the links at addresses that have none, making room for each. The addresses named are not evicted for each other.
public virtual void EnsureCreated(params TLinkAddress[] addresses)
Parameters
addressesTLinkAddress[]
Expire(TLinkAddress, ulong)
Gives link a deadline in place of any it had; false when there is no such link. A time of zero deletes it now, as Redis EXPIRE does.
public bool Expire(TLinkAddress link, ulong milliseconds)
Parameters
linkTLinkAddressmillisecondsulong
Returns
GetByName(string)
public virtual TLinkAddress GetByName(string name)
Parameters
namestring
Returns
- TLinkAddress
GetName(TLinkAddress)
public virtual string? GetName(TLinkAddress link)
Parameters
linkTLinkAddress
Returns
Persist(TLinkAddress)
Takes the deadline of link away; false when it had none.
public bool Persist(TLinkAddress link)
Parameters
linkTLinkAddress
Returns
PurgeExpired()
Deletes what is due now; returns how many links that deleted, cascades included.
public int PurgeExpired()
Returns
RemoveName(TLinkAddress)
public virtual void RemoveName(TLinkAddress link)
Parameters
linkTLinkAddress
SetName(TLinkAddress, string)
public virtual TLinkAddress SetName(TLinkAddress link, string name)
Parameters
linkTLinkAddressnamestring
Returns
- TLinkAddress
TimeToLive(TLinkAddress)
The milliseconds link has left; null when it has no deadline or is gone.
public ulong? TimeToLive(TLinkAddress link)
Parameters
linkTLinkAddress
Returns
Update(IList<TLinkAddress>?, IList<TLinkAddress>?, WriteHandler<TLinkAddress>?)
Updates the restriction.
public override TLinkAddress Update(IList<TLinkAddress>? restriction, IList<TLinkAddress>? substitution, WriteHandler<TLinkAddress>? handler)
Parameters
restrictionIList<TLinkAddress>The restriction.
substitutionIList<TLinkAddress>The substitution.
handlerWriteHandler<TLinkAddress>Optional callback; null continues without invoking a callback.
Returns
- TLinkAddress
The link