@baeta/extension-cache
Classes
CacheRef<Result, Root, Args>
Cache reference for a type field or query
Type Parameters
Type Parameter |
---|
|
|
|
Constructors
new CacheRef()
new CacheRef<
Result
,Root
,Args
>(type
,field
,hash
,revision
):CacheRef
<Result
,Root
,Args
>
Parameters
Parameter | Type | Default value |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Returns
CacheRef
<Result
, Root
, Args
>
Methods
getHash()
getHash():
string
Returns
string
getRevision()
getRevision():
number
Returns
number
setRevision()
setRevision(
revision
):void
Parameters
Parameter | Type |
---|---|
|
|
Returns
void
toString()
toString():
string
Returns
string
abstract
Store
Base class for cache storage implementations
Constructors
new Store()
new Store():
Store
Returns
Methods
createStoreAdapter()
abstract
createStoreAdapter<T
>(options
,type
,hash
):StoreAdapter
<T
>
Creates a new store adapter for a specific type
Type Parameters
Type Parameter |
---|
|
Parameters
Parameter | Type | Description |
---|---|---|
|
|
Store configuration options |
|
|
Type name for the cached items |
|
|
Unique hash for the type |
Returns
StoreAdapter
<T
>
abstract
StoreAdapter<Item>
Type Parameters
Type Parameter |
---|
|
Constructors
new StoreAdapter()
new StoreAdapter<
Item
>(options
,type
,hash
):StoreAdapter
<Item
>
Parameters
Parameter | Type |
---|---|
|
|
|
|
|
|
Returns
StoreAdapter
<Item
>
Properties
Property | Modifier | Type |
---|---|---|
|
|
( |
|
|
< |
|
|
( |
|
|
|
|
| |
|
|
( |
|
|
|
|
|
( |
|
|
( |
|
|
|
Methods
createKey()
protected
createKey(ref
):string
Parameters
Parameter | Type |
---|---|
|
Returns
string
createKeyByItem()
protected
createKeyByItem(item
):string
Parameters
Parameter | Type |
---|---|
|
|
Returns
string
createKeyByQuery()
protected
createKeyByQuery(queryRef
,parentRef
?,args
?):string
Parameters
Parameter | Type |
---|---|
|
|
| |
|
|
Returns
string
createMiddleware()
createMiddleware<
Result
,Root
,Args
>(queryRef
, ...args
):Middleware
<Result
,Root
,unknown
,Args
>
Type Parameters
Type Parameter |
---|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
... |
|
Returns
Middleware
<Result
, Root
, unknown
, Args
>
createQueryKeyGlobMatcher()
protected
createQueryKeyGlobMatcher(queryRef
,parentRef
,args
):string
Parameters
Parameter | Type |
---|---|
|
|
|
|
|
|
Returns
string
createQueryKeyHeader()
protected
createQueryKeyHeader(parentRef
,args
?):string
Parameters
Parameter | Type |
---|---|
| |
|
|
Returns
string
createQueryKeyNamespace()
protected
createQueryKeyNamespace(queryRef
):string
Parameters
Parameter | Type |
---|---|
|
|
Returns
string
createQueryKeyRegExpMatcher()
protected
createQueryKeyRegExpMatcher(queryRef
,parentRef
,args
):RegExp
Parameters
Parameter | Type |
---|---|
|
|
|
|
|
|
Returns
RegExp
decodeQueryItemRef()
protected
decodeQueryItemRef(encodedRef
):null
|string
Parameters
Parameter | Type |
---|---|
|
|
Returns
null
| string
delete()
delete(
ref
,evictQueries
?):Promise
<void
>
Parameters
Parameter | Type |
---|---|
| |
|
|
Returns
Promise
<void
>
deleteQueries()
deleteQueries<
Result
,Root
,Args
>(queryRef
?,matcher
?):Promise
<void
>
Type Parameters
Type Parameter |
---|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
Promise
<void
>
encodePrimitive()
protected
encodePrimitive(value
,catchAll
?):null
|string
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
null
| string
encodeProperty()
protected
encodeProperty(value
):string
Parameters
Parameter | Type |
---|---|
|
|
Returns
string
encodeQueryArgs()
protected
encodeQueryArgs(args
,catchAll
?):string
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
string
encodeQueryItemRef()
protected
encodeQueryItemRef(item
):string
Parameters
Parameter | Type |
---|---|
|
|
Returns
string
get()
get(
ref
):Promise
<null
|Item
>
Parameters
Parameter | Type |
---|---|
|
Returns
Promise
<null
| Item
>
getMany()
getMany(
refs
):Promise
<null
|Item
[]>
Parameters
Parameter | Type |
---|---|
|
|
Returns
Promise
<null
| Item
[]>
getQueryResult()
getQueryResult<
Result
,Root
,Args
>(queryRef
,matcher
?):Promise
<null
| {query
:Result
; }>
Type Parameters
Type Parameter |
---|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
|
|
Returns
Promise
<null
| { query
: Result
; }>
getRef()
protected
getRef(root
):ItemRef
Parameters
Parameter | Type |
---|---|
|
|
Returns
getRefFallback()
protected
getRefFallback(root
):undefined
|string
Parameters
Parameter | Type |
---|---|
|
|
Returns
undefined
| string
getRevision()
protected
getRevision():string
Returns
string
loaderFn()
protected
loaderFn(refs
):Promise
<any
[]>
Parameters
Parameter | Type |
---|---|
|
readonly |
Returns
Promise
<any
[]>
refillNullQueryItems()
protected
refillNullQueryItems(nullableRefs
,items
): (null
|Item
)[]
Parameters
Parameter | Type |
---|---|
|
( |
|
|
Returns
(null
| Item
)[]
save()
save(
item
):Promise
<void
>
Parameters
Parameter | Type |
---|---|
|
|
Returns
Promise
<void
>
saveQueryResult()
saveQueryResult<
Result
,Root
,Args
>(queryRef
,data
,matcher
?):Promise
<void
>
Type Parameters
Type Parameter |
---|
|
|
|
Parameters
Parameter | Type |
---|---|
|
|
|
|
|
|
Returns
Promise
<void
>
shouldEncode()
protected
shouldEncode(value
):boolean
Parameters
Parameter | Type |
---|---|
|
|
Returns
boolean
validateRefType()
protected
validateRefType(ref
): asserts ref is string | number | bigint
Parameters
Parameter | Type |
---|---|
|
|
Returns
asserts ref is string | number | bigint
Interfaces
CacheMiddlewareOptions<Root>
Options for cache middleware
Extended by
Type Parameters
Type Parameter |
---|
|
Properties
Property | Type | Description |
---|---|---|
|
( |
Function to extract object reference id |
DefaultStoreOptions
Default options for cache stores
Extended by
Properties
Property | Type | Default value | Description |
---|---|---|---|
|
|
|
Time-to-live in seconds |
RequiredCacheMiddlewareOptions<Root>
Required options for cache middleware
Extends
CacheMiddlewareOptions
<Root
>
Type Parameters
Type Parameter |
---|
|
Properties
Property | Type | Description | Overrides |
---|---|---|---|
|
( |
Function to extract object reference id |
RequiredStoreOptions<Root>
Required configuration options for cache stores
Extends
StoreOptions
<Root
>
Type Parameters
Type Parameter |
---|
|
Properties
Property | Type | Default value | Description | Overrides | Inherited from |
---|---|---|---|---|---|
|
( |
|
Function to extract object reference id |
‐ | |
|
|
|
Manual cache version for invalidation |
‐ | |
|
|
|
Time-to-live in seconds |
‐ |
StoreOptions<Root>
Configuration options for cache stores
Extends
Extended by
Type Parameters
Type Parameter |
---|
|
Properties
Property | Type | Default value | Description | Inherited from |
---|---|---|---|---|
|
( |
|
Function to extract object reference id |
‐ |
|
|
|
Manual cache version for invalidation |
‐ |
|
|
|
Time-to-live in seconds |
Type Aliases
CacheArgs<T>
CacheArgs<
T
>:{ [P in keyof T]?: T[P] extends object ? CacheArgs<T[P]> : T[P] }
Optional query arguments
Type Parameters
Type Parameter |
---|
|
CacheQueryMatching<Args>
CacheQueryMatching<
Args
>:object
Type Parameters
Type Parameter |
---|
|
Type declaration
Name | Type |
---|---|
|
|
|
ItemRef
ItemRef:
string
|number
|bigint
Reference type for cached items
ParentRef
ParentRef:
ItemRef
|null
|undefined
Reference type for query parent
RefCompatibleRoot
RefCompatibleRoot: {
id
:string
|number
|bigint
; } | {}
Type constraint for objects that are compatible with default cache ref
Functions
cacheExtension()
cacheExtension(
store
,options
?): () =>Extension
Creates a cache extension
Parameters
Parameter | Type | Description |
---|---|---|
|
Storage adapter implementation | |
|
Default caching options |
Returns
Function
Extension factory function
Returns
Extension
Example
import { cacheExtension } from "@baeta/extension-cache";
import { RedisStore } from "@baeta/extension-cache-redis";
import Redis from "ioredis";
const redis = new Redis("redis://localhost:6379");
const redisStore = new RedisStore(redis);
export const cacheExt = cacheExtension(redisStore, {
ttl: 3600, // TTL in seconds (defaults to 1 hour)
});