@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
| Name | Type | Description |
|---|---|---|
T | any | Type of the cached data. |
Implements
CachePolicy<T>
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
| Name | Type | Description |
|---|---|---|
T | any | Type of the cached data. |
Parameters
| Name | Type | Description |
|---|---|---|
ttl | number | Time 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
| Name | Type | Description |
|---|---|---|
item | CacheItem<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.
Starboard