PerspectPerspectDocs
Go to Admin
View as Markdown

cache-manager

Classes

  • CacheManager

cloudflare-kv-adapter

Classes

  • CloudflareKVCacheAdapter

Interfaces

  • KVLike

in-memory-adapter

Classes

  • InMemoryCacheAdapter

noop-adapter

Classes

  • NoopCacheAdapter

perspectapi-ts-sdk

Modules

  • cache-manager
  • cloudflare-kv-adapter
  • in-memory-adapter
  • noop-adapter
  • types

types

Interfaces

  • CacheAdapter
  • CacheConfig
  • CacheEntry
  • CacheInvalidateOptions
  • CacheManagerOptions
  • CachePolicy
  • CacheSetOptions

Type Aliases

  • CacheKeyPart

Interface: KVLike

Minimal interface matching CloudflareKvAdapter / CacheStorage from @perspect/shared.

Methods

clear()?

optional clear(): Promise<void>

Returns

Promise<void>

delete()

delete(key): Promise<void>

Parameters

key

string

Returns

Promise<void>

deleteMultiple()?

optional deleteMultiple(keys): Promise<void>

Parameters

keys

string[]

Returns

Promise<void>

get()

get(key): Promise<string | null>

Parameters

key

string

Returns

Promise<string | null>

put()

put(key, value, options?): Promise<void>

Parameters

key

string

value

string

options?
expirationTtl?

number

Returns

Promise<void>


Interface: CacheAdapter

Methods

clear()?

optional clear(): Promise<void>

Optional clear method to wipe all entries for adapters that manage isolated namespaces.

Returns

Promise<void>

delete()

delete(key): Promise<void>

Remove a cached entry.

Parameters

key

string

Returns

Promise<void>

deleteMany()?

optional deleteMany(keys): Promise<void>

Optional bulk delete implementation.

Parameters

keys

string[]

Returns

Promise<void>

get()

get(key): Promise<string | null | undefined>

Retrieve a raw cache payload for the given key. Implementations should return undefined (or null) when the key does not exist or has expired.

Parameters

key

string

Returns

Promise<string | null | undefined>

set()

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

Store a raw payload for the given key. Implementations MAY honour ttlSeconds natively; the cache manager will also persist expiry timestamps in the payload for adapters that do not have native TTL support.

Parameters

key

string

value

string

options?
ttlSeconds?

number

Returns

Promise<void>


Interface: CacheConfig

Extends

  • CacheManagerOptions

Properties

adapter?

optional adapter?: CacheAdapter

defaultTtlSeconds?

optional defaultTtlSeconds?: number

Inherited from

CacheManagerOptions.defaultTtlSeconds

enabled?

optional enabled?: boolean

Explicit flag to disable caching. Defaults to false when a cache configuration is supplied, so caching is considered enabled unless explicitly disabled.

keyPrefix?

optional keyPrefix?: string

Inherited from

CacheManagerOptions.keyPrefix


Interface: CacheEntry<T>

Type Parameters

T

T = unknown

Properties

expiresAt?

optional expiresAt?: number

metadata?

optional metadata?: Record<string, unknown>

tags?

optional tags?: string[]

value

value: T


Interface: CacheInvalidateOptions

Properties

keys?

optional keys?: string[]

tags?

optional tags?: string[]


Interface: CacheManagerOptions

Extended by

  • CacheConfig

Properties

defaultTtlSeconds?

optional defaultTtlSeconds?: number

keyPrefix?

optional keyPrefix?: string


Interface: CachePolicy

Extends

  • CacheSetOptions

Properties

metadata?

optional metadata?: Record<string, unknown>

Inherited from

CacheSetOptions.metadata

skipCache?

optional skipCache?: boolean

tags?

optional tags?: string[]

Inherited from

CacheSetOptions.tags

ttlSeconds?

optional ttlSeconds?: number

Inherited from

CacheSetOptions.ttlSeconds


Interface: CacheSetOptions

Extended by

  • CachePolicy

Properties

metadata?

optional metadata?: Record<string, unknown>

tags?

optional tags?: string[]

ttlSeconds?

optional ttlSeconds?: number


Type Alias: CacheKeyPart

CacheKeyPart = string | number | boolean | null | undefined | Record<string, unknown> | (Record<string, unknown> | string | number | boolean | null | undefined)[]

Cache-related types for the PerspectAPI SDK.


Class: CacheManager

Constructors

Constructor

new CacheManager(config?): CacheManager

Parameters

config?

CacheConfig

Returns

CacheManager

Methods

buildKey()

buildKey(parts): string

Parameters

parts

CacheKeyPart[]

Returns

string

delete()

delete(key): Promise<void>

Parameters

key

string

Returns

Promise<void>

getKeyPrefix()

getKeyPrefix(): string

Returns

string

getOrSet()

getOrSet<T>(key, resolveValue, policy?): Promise<T>

Type Parameters

T

T

Parameters

key

string

resolveValue

() => Promise<T>

policy?

CachePolicy

Returns

Promise<T>

invalidate()

invalidate(options): Promise<void>

Parameters

options

CacheInvalidateOptions

Returns

Promise<void>

isEnabled()

isEnabled(): boolean

Returns

boolean

set()

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

Type Parameters

T

T

Parameters

key

string

value

T

options?

CacheSetOptions

Returns

Promise<void>


Class: CloudflareKVCacheAdapter

Implements

  • CacheAdapter

Constructors

Constructor

new CloudflareKVCacheAdapter(kv): CloudflareKVCacheAdapter

Parameters

kv

KVLike

Returns

CloudflareKVCacheAdapter

Methods

clear()

clear(): Promise<void>

Optional clear method to wipe all entries for adapters that manage isolated namespaces.

Returns

Promise<void>

Implementation of

CacheAdapter.clear

delete()

delete(key): Promise<void>

Remove a cached entry.

Parameters

key

string

Returns

Promise<void>

Implementation of

CacheAdapter.delete

deleteMany()

deleteMany(keys): Promise<void>

Optional bulk delete implementation.

Parameters

keys

string[]

Returns

Promise<void>

Implementation of

CacheAdapter.deleteMany

get()

get(key): Promise<string | null>

Retrieve a raw cache payload for the given key. Implementations should return undefined (or null) when the key does not exist or has expired.

Parameters

key

string

Returns

Promise<string | null>

Implementation of

CacheAdapter.get

set()

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

Store a raw payload for the given key. Implementations MAY honour ttlSeconds natively; the cache manager will also persist expiry timestamps in the payload for adapters that do not have native TTL support.

Parameters

key

string

value

string

options?
ttlSeconds?

number

Returns

Promise<void>

Implementation of

CacheAdapter.set


Class: InMemoryCacheAdapter

Implements

  • CacheAdapter

Constructors

Constructor

new InMemoryCacheAdapter(): InMemoryCacheAdapter

Returns

InMemoryCacheAdapter

Methods

clear()

clear(): Promise<void>

Optional clear method to wipe all entries for adapters that manage isolated namespaces.

Returns

Promise<void>

Implementation of

CacheAdapter.clear

delete()

delete(key): Promise<void>

Remove a cached entry.

Parameters

key

string

Returns

Promise<void>

Implementation of

CacheAdapter.delete

deleteMany()

deleteMany(keys): Promise<void>

Optional bulk delete implementation.

Parameters

keys

string[]

Returns

Promise<void>

Implementation of

CacheAdapter.deleteMany

get()

get(key): Promise<string | undefined>

Retrieve a raw cache payload for the given key. Implementations should return undefined (or null) when the key does not exist or has expired.

Parameters

key

string

Returns

Promise<string | undefined>

Implementation of

CacheAdapter.get

set()

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

Store a raw payload for the given key. Implementations MAY honour ttlSeconds natively; the cache manager will also persist expiry timestamps in the payload for adapters that do not have native TTL support.

Parameters

key

string

value

string

options?
ttlSeconds?

number

Returns

Promise<void>

Implementation of

CacheAdapter.set


Class: NoopCacheAdapter

Implements

  • CacheAdapter

Constructors

Constructor

new NoopCacheAdapter(): NoopCacheAdapter

Returns

NoopCacheAdapter

Methods

clear()

clear(): Promise<void>

Optional clear method to wipe all entries for adapters that manage isolated namespaces.

Returns

Promise<void>

Implementation of

CacheAdapter.clear

delete()

delete(): Promise<void>

Remove a cached entry.

Returns

Promise<void>

Implementation of

CacheAdapter.delete

deleteMany()

deleteMany(): Promise<void>

Optional bulk delete implementation.

Returns

Promise<void>

Implementation of

CacheAdapter.deleteMany

get()

get(): Promise<undefined>

Retrieve a raw cache payload for the given key. Implementations should return undefined (or null) when the key does not exist or has expired.

Returns

Promise<undefined>

Implementation of

CacheAdapter.get

set()

set(): Promise<void>

Store a raw payload for the given key. Implementations MAY honour ttlSeconds natively; the cache manager will also persist expiry timestamps in the payload for adapters that do not have native TTL support.

Returns

Promise<void>

Implementation of

CacheAdapter.set