Skip to content

Classes

Cache

Defined in: index.ts:57

Extends

Constructors

new Cache()
new Cache(options): Cache

Defined in: index.ts:94

Parameters
options

CacheOptions

Returns

Cache

Overrides
LRUCache<
string,
Buffer,
CacheFetchContext
>.constructor

Properties

[toStringTag]
[toStringTag]: string = '@vltpkg/cache.Cache';

Defined in: index.ts:63

Overrides
LRUCache.[toStringTag]
onDiskDelete()?
optional onDiskDelete: (path, key, deleted) => any;

Defined in: index.ts:68

Parameters
path

string

key

string

deleted

boolean

Returns

any

onDiskWrite()?
optional onDiskWrite: (path, key, data) => any;

Defined in: index.ts:67

Parameters
path

string

key

string

data

Buffer

Returns

any

Accessors

pending
Get Signature
get pending(): Promise<BooleanOrVoid>[]

Defined in: index.ts:82

A list of the actions currently happening in the background

Returns

Promise<BooleanOrVoid>[]

random
Get Signature
get random(): string

Defined in: index.ts:75

ensure we get a different random key for every write, just in case the same file tries to write multiple times, it’ll still be atomic.

Returns

string

defaultMax
Get Signature
get static defaultMax(): number

Defined in: index.ts:90

By default, cache up to 1000 items in memory. Disk cache is unbounded.

Returns

number

Methods

[asyncIterator]()
asyncIterator: AsyncGenerator<[string, Buffer], void, void>

Defined in: index.ts:152

Returns

AsyncGenerator<[string, Buffer], void, void>

[iterator]()
iterator: Generator<[string, Buffer], void>

Defined in: index.ts:183

Returns

Generator<[string, Buffer], void>

Overrides
LRUCache.[iterator]
delete()
delete(key, fromDisk): boolean

Defined in: index.ts:204

Pass true as second argument to delete not just from the in-memory cache, but the disk backing as well.

Parameters
key

string

fromDisk

boolean = false

Returns

boolean

Overrides
LRUCache.delete
fetchSync()
fetchSync(key, opts?): undefined | Buffer

Defined in: index.ts:301

Read synchronously from the fs cache storage if not already in memory.

Parameters
key

string

opts?

FetchOptions<string, Buffer, CacheFetchContext>

Returns

undefined | Buffer

integrityPath()
integrityPath(integrity?): undefined | string

Defined in: index.ts:283

given an SRI sha512 integrity string, get the path on disk that is hard-linked to the value.

Parameters
integrity?

`sha512-${string}`

Returns

undefined | string

path()
path(key): string

Defined in: index.ts:276

given a key, figure out the path on disk where it lives

Parameters
key

string

Returns

string

promise()
promise(): Promise<void>

Defined in: index.ts:267

Resolves when there are no pending writes to the disk cache

Returns

Promise<void>

set()
set(
key,
val,
options?): Cache

Defined in: index.ts:229

Sets an item in the memory cache (like LRUCache.set), and schedules a background operation to write it to disk.

Use the CacheOptions#onDiskWrite method to know exactly when this happens, or await cache.promise() to defer until all pending actions are completed.

The noDiskWrite option can be set to prevent it from writing back to the disk cache. This is almost never relevant for consumers, and is used internally to prevent the write at the end of fetch() from excessively writing over a file we just read from.

Parameters
key

string

val

Buffer

options?

SetOptions<string, Buffer, CacheFetchContext> & object

Returns

Cache

Overrides
LRUCache.set
walk()
walk(): AsyncGenerator<[string, Buffer], void>

Defined in: index.ts:133

Walk over all the items cached to disk (not just in memory). Useful for cleanup, pruning, etc.

Implementation for for await to walk over entries.

Returns

AsyncGenerator<[string, Buffer], void>

walkSync()
walkSync(): Generator<[string, Buffer], void>

Defined in: index.ts:163

Synchronous form of Cache.walk()

Returns

Generator<[string, Buffer], void>

Type Aliases

BooleanOrVoid

type BooleanOrVoid = boolean | void

Defined in: index.ts:52


CacheFetchContext

type CacheFetchContext =
| {
integrity: Integrity
}
| undefined

Defined in: index.ts:19


CacheOptions

type CacheOptions = {
[k in keyof LRUCache.Options<
string,
Buffer,
CacheFetchContext
>]?: LRUCache.Options<string, Buffer, CacheFetchContext>[k]
} & object

Defined in: index.ts:25

Type declaration

fetchMethod?
optional fetchMethod: undefined;

fetchMethod may not be provided, because this cache forces its own read-from-disk as the fetchMethod

onDiskDelete()?
optional onDiskDelete: (path, key, deleted) => any;

called whenever an item is deleted with cache.delete(key, true) Deletes of the in-memory data do not trigger this method.

Parameters
path

string

key

string

deleted

boolean

Returns

any

onDiskWrite()?
optional onDiskWrite: (path, key, data) => any;

called whenever an item is written to disk.

Parameters
path

string

key

string

data

Buffer

Returns

any

path
path: string

folder where items should be stored to disk