Skip to content

SlidingCache2 Constructors` ​

Definition ​

  • Namespace: JASE.Caching
  • Assembly: JASE.Caching.dll

Overloads ​

NameDescription
`SlidingCache`2(TimeSpan slidingTtl, int maxEntries)`Initializes a new SlidingCache`2 with a sliding expiration and a fixed maximum size.
`SlidingCache`2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds)`Initializes a new cache instance.
`SlidingCache`2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds, TimeSpan minPruneInterval)`Initializes a new cache instance with an explicit minimum prune interval.
`SlidingCache`2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds, TimeSpan? minPruneInterval, Func<TKey, TValue, SlidingCacheEvictionReason, bool> evictCallback)`Initializes a new cache instance with optional pruning and eviction callback configuration.

SlidingCache2(TimeSpan slidingTtl, int maxEntries)` ​

csharp
SlidingCache`2(TimeSpan slidingTtl, int maxEntries)

Initializes a new SlidingCache`2 with a sliding expiration and a fixed maximum size.

Parameters ​

NameDescription
maxEntriesMaximum number of entries to retain in the cache. When exceeded, older entries are evicted using an approximate LRU strategy.
slidingTtlSliding time-to-live for cache entries. Each successful read refreshes the expiration timer so the entry remains valid for this duration since its most recent access.

Remarks ​

This overload uses default pruning behavior tuned for general use:

Pruning is triggered opportunistically during reads and writes, rather than on a dedicated timer.

Eviction is based on sliding expiration and size pressure, using an approximate LRU strategy to avoid global locks.

No eviction callback is registered; values that implement IDisposable are disposed automatically when evicted.

SlidingCache2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds)` ​

csharp
SlidingCache`2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds)

Initializes a new cache instance.

Parameters ​

NameDescription
maxEntriesMaximum number of entries to retain before size-based eviction is applied.
slidingTtlSliding time-to-live. Each successful read refreshes the entry so it remains valid for this duration since the last access.
trimEveryNAddsControls how frequently prune work is triggered by adds. Reads trigger pruning at a lower frequency (internally scaled from this value).

SlidingCache2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds, TimeSpan minPruneInterval)` ​

csharp
SlidingCache`2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds, TimeSpan minPruneInterval)

Initializes a new cache instance with an explicit minimum prune interval.

Parameters ​

NameDescription
maxEntriesMaximum number of entries to retain.
minPruneIntervalMinimum interval between time-based prune runs. Use Zero to effectively disable time-based pruning; size-based pruning still occurs when capacity is exceeded.
slidingTtlSliding time-to-live.
trimEveryNAddsControls how frequently prune work is triggered by adds.

SlidingCache2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds, TimeSpan? minPruneInterval, Func<TKey, TValue, SlidingCacheEvictionReason, bool> evictCallback)` ​

csharp
SlidingCache`2(TimeSpan slidingTtl, int maxEntries, int trimEveryNAdds, TimeSpan? minPruneInterval, Func<TKey, TValue, SlidingCacheEvictionReason, bool> evictCallback)

Initializes a new cache instance with optional pruning and eviction callback configuration.

Parameters ​

NameDescription
evictCallbackOptional callback invoked when an entry is evicted (expired, replaced, removed, or size-based). Return true to indicate the callback assumes ownership of the value (and will dispose it if applicable). Return false to allow the cache to dispose values that implement IDisposable.
maxEntriesMaximum number of entries to retain.
minPruneIntervalMinimum interval between time-based prune runs. If null, MinimalPruneIntervalDefault is used. Use Zero to disable time-based pruning; size-based pruning still occurs when capacity is exceeded.
slidingTtlSliding time-to-live.
trimEveryNAddsControls how frequently prune work is triggered by adds.