Skip to content

@mcsb/api / Exports / TTLCachePolicy

Class: TTLCachePolicy<T>

Time-based implementation of CachePolicy. CacheItem entries are considered valid for a given amount of time after entrance into the {Cache.

Type parameters

NameTypeDescription
TanyType of the cached data.

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new TTLCachePolicy<T>(ttl)

Create a new CachePolicy which marks items as expired after a certain amount of time.

Type parameters

NameTypeDescription
TanyType of the cached data.

Parameters

NameTypeDescription
ttlnumberTime to live in milliseconds. After this number of milliseconds since the CacheItem was saved, the CacheItem will no longer be used and can safely be removed from the cache.

Defined in

packages/api/src/cache/TTLCachePolicy.ts:23

Properties

ttl

Readonly ttl: number

Number of milliseconds after CacheItem entry after which point the entry will no longer be valid, and should be garbage collected.

Defined in

packages/api/src/cache/TTLCachePolicy.ts:15

Methods

check

check(item): boolean | Promise<boolean>

Check if a given CacheItem is still valid according to this policy.

Parameters

NameTypeDescription
itemCacheItem<T>CacheItem to check.

Returns

boolean | Promise<boolean>

true if the CacheItem's creation time plus the TTL is still in the future, false otherwise.

Implementation of

CachePolicy.check

Defined in

packages/api/src/cache/TTLCachePolicy.ts:36

Released under the MIT License.