@mcsb/api / Exports / CachePolicy
Interface: CachePolicy<T>
A CachePolicy
is an interface for checking whether a given object of type T
is considered a "hit" or "miss" on the cache. Typically, this will take into account how stale the data is. For simple use-cases, you can simply use TTLCachePolicy.
See
Type parameters
Name | Type | Description |
---|---|---|
T | any | The type of the object stored in the cache. |
Implemented by
Table of contents
Methods
Methods
check
▸ check(item
): boolean
| Promise
<boolean
>
Checks whether the given item is considered a "hit" or "miss" on the Cache. If it is a hit, then the Cache should keep the data and keep handing it out to callers. If it is a miss, then the Cache should not return the data anymore, and it's free to delete it from the cache.
Parameters
Name | Type | Description |
---|---|---|
item | CacheItem <T > | The item to check, containing both the value of type T and the time at which it was first inserted into the Cache. |
Returns
boolean
| Promise
<boolean
>
A boolean
representing whether the item is considered a "hit" or "miss". Can also return a Promise<boolean>
. If it is a miss, the Cache should no longer use it, and it's safe to delete it.