Skip to main content
zerotal

Documentation


Documentation / @zerotal/cache / index / TaggedCache

Class: TaggedCache

Defined in: cache/src/CacheManager.ts:190

Extends

Constructors

Constructor

new TaggedCache(_driver, _prefix?, _defaultTtl?, _lock?, _stampedeProtection?): TaggedCache

Defined in: cache/src/CacheManager.ts:19

Parameters

_driver

CacheDriver

_prefix?

string = ""

_defaultTtl?

number

_lock?

LockManager | null

_stampedeProtection?

boolean = true

Returns

TaggedCache

Inherited from

CacheManager.constructor

Methods

get()

get<T>(key): Promise<T | null>

Defined in: cache/src/CacheManager.ts:49

Type Parameters

T

T

Parameters

key

string

Returns

Promise<T | null>

Inherited from

CacheManager.get


set()

set(key, value, ttl?): Promise<void>

Defined in: cache/src/CacheManager.ts:59

Parameters

key

string

value

unknown

ttl?

number

Returns

Promise<void>

Inherited from

CacheManager.set


forget()

forget(key): Promise<void>

Defined in: cache/src/CacheManager.ts:66

Parameters

key

string

Returns

Promise<void>

Inherited from

CacheManager.forget


has()

has(key): Promise<boolean>

Defined in: cache/src/CacheManager.ts:72

Parameters

key

string

Returns

Promise<boolean>

Inherited from

CacheManager.has


flush()

flush(): Promise<void>

Defined in: cache/src/CacheManager.ts:79

Returns

Promise<void>

Inherited from

CacheManager.flush


remember()

remember<T>(key, ttl, fn): Promise<T>

Defined in: cache/src/CacheManager.ts:85

Type Parameters

T

T

Parameters

key

string

ttl

number

fn

() => T | Promise<T>

Returns

Promise<T>

Inherited from

CacheManager.remember


forever()

forever(key, value): Promise<void>

Defined in: cache/src/CacheManager.ts:147

Parameters

key

string

value

unknown

Returns

Promise<void>

Inherited from

CacheManager.forever


tags()

tags(tagNames): TaggedCache

Defined in: cache/src/CacheManager.ts:171

Scope reads/writes to a tag namespace. Tags are a deterministic, ordered namespace: tags([...]) sorts and joins the names into a key prefix, so tags(['a','b']) and tags(['b','a']) address the same entries (the order no longer matters), and tags([...]).flush() clears exactly that namespace.

Note: this is namespacing, not a per-tag index — flushing tags(['b']) does NOT invalidate entries written under tags(['a','b']). Flush with the same tag set you wrote with. (A true multi-tag index — where any one tag can invalidate every entry carrying it — is intentionally out of scope for v1.)

The namespace is a fixed-length digest of the sorted tag list rather than the names joined together, because flush() is a prefix delete and a joined prefix contains its own sub-namespaces: tags(['a']) produced a:, which matches a:b:key, so flushing ['a'] wiped the ['a','b'] namespace this docblock promises it will not. A digest also stops a tag that happens to contain the separator from colliding — tags(['a:b']) and tags(['a','b']) are different namespaces.

Parameters

tagNames

string[]

Returns

TaggedCache

Inherited from

CacheManager.tags


dispose()

dispose(): void

Defined in: cache/src/CacheManager.ts:185

Returns

void

Inherited from

CacheManager.dispose