Table of Contents

Class SynchronizedObject<T>

Namespace
ToSic.Eav.Caching
Assembly
ToSic.Eav.Core.dll

WIP 12.03

[InternalApi_DoNotUse_MayChangeWithoutNotice("this is just fyi")]
public class SynchronizedObject<T> : ICacheDependent, ICacheExpiring, ITimestamped

Type Parameters

T

The type which is enumerated, usually an IEntity

Inheritance
SynchronizedObject<T>
Implements
Derived

Constructors

SynchronizedObject(ICacheExpiring, Func<T>)

Initialized a new list which depends on another source

public SynchronizedObject(ICacheExpiring upstream, Func<T> rebuild)

Parameters

upstream ICacheExpiring

the upstream cache which can tell us if a refresh is necessary

rebuild Func<T>

the method which rebuilds the list

Fields

Cache

The cached object/result

protected T Cache

Field Value

T

RebuildCache

A callback to rebuild the cache which is provided when this object is created

protected readonly Func<T> RebuildCache

Field Value

Func<T>

RebuildCount

Counter to see how often the cache had been reset.

public int RebuildCount

Field Value

int

Upstream

Upstream source which implements ICacheExpiring to tell this object when the data must be refreshed

protected readonly ICacheExpiring Upstream

Field Value

ICacheExpiring

Properties

CacheTimestamp

System time-stamp of when the data in this cached thing was initialized or updated. Depending on the implementation, this may go up-stream and return an up-stream value.

public long CacheTimestamp { get; }

Property Value

long

A timestamp as a long number

Value

Retrieves the list - either the cache one, or if timestamp has changed, rebuild and return that

public virtual T Value { get; }

Property Value

T

Methods

CacheChanged()

Find out if the source it depends on has changed.

public bool CacheChanged()

Returns

bool

True if the upstream cache returns a newer timestamp

CacheChanged(long)

Detect if the cache has newer data. It's called using the TimeStamp of the dependent object which may still have old data.

public bool CacheChanged(long dependentTimeStamp)

Parameters

dependentTimeStamp long

New time stamp of a dependent object, which could have an older timestamp.

Returns

bool

True if the timestamps differ, false if it's the same

Remarks

This is implemented in each object, because sometimes it compares its own timestamp, sometimes that of another underlying object.