Reference
Classes
Cache
Defined in: index.ts:70
Extends
LRUCache<string,Buffer,CacheFetchContext>
Constructors
new Cache()
new Cache(options): CacheDefined in: index.ts:99
Parameters
| Parameter | Type |
|---|---|
options | CacheOptions |
Returns
Overrides
LRUCache<
string,
Buffer,
CacheFetchContext
>.constructorProperties
| Property | Type | Default value | Overrides |
|---|---|---|---|
[toStringTag] | string | '@vltpkg/cache.Cache' | LRUCache.[toStringTag] |
onDiskDelete? | (path: string, key: string, deleted: boolean) => any | undefined | - |
onDiskWrite? | (path: string, key: string, data: Buffer) => any | undefined | - |
store? | string | undefined | - |
Accessors
pending
Get Signature
get pending(): Promise<BooleanOrVoid>[]Defined in: index.ts:87
A list of the actions currently happening in the background
Returns
Promise<BooleanOrVoid>[]
defaultMax
Get Signature
get static defaultMax(): numberDefined in: index.ts:95
By default, cache up to 1000 items in memory. Disk cache is unbounded.
Returns
number
Methods
[asyncIterator]()
asyncIterator: AsyncGenerator<[string, Buffer<ArrayBufferLike>], void, void>Defined in: index.ts:161
Returns
AsyncGenerator<[string, Buffer<ArrayBufferLike>], void, void>
[iterator]()
iterator: Generator<[string, Buffer<ArrayBufferLike>], void>Defined in: index.ts:193
Returns
Generator<[string, Buffer<ArrayBufferLike>], void>
Overrides
LRUCache.[iterator]delete()
delete(
key,
fromDisk,
integrity?): booleanDefined in: index.ts:214
Pass true as second argument to delete not just from the in-memory
cache, but the disk backing as well.
Parameters
| Parameter | Type | Default value |
|---|---|---|
key | string | undefined |
fromDisk | boolean | false |
integrity? | `sha512-${string}` | undefined |
Returns
boolean
Overrides
LRUCache.deletefetchSync()
fetchSync(key, opts?): undefined | Buffer<ArrayBufferLike>Defined in: index.ts:314
Read synchronously from the fs cache storage if not already in memory.
Parameters
| Parameter | Type |
|---|---|
key | string |
opts? | FetchOptions<string, Buffer<ArrayBufferLike>, CacheFetchContext> |
Returns
undefined | Buffer<ArrayBufferLike>
integrityPath()
integrityPath(integrity?): undefined | stringDefined in: index.ts:298
given an SRI sha512 integrity string, get the path on disk that is hard-linked to the value.
Parameters
| Parameter | Type |
|---|---|
integrity? | `sha512-${string}` |
Returns
undefined | string
path()
path(key?): stringDefined in: index.ts:291
given a key, figure out the path on disk where it lives
Parameters
| Parameter | Type |
|---|---|
key? | string |
Returns
string
promise()
promise(): Promise<void>Defined in: index.ts:282
Resolves when there are no pending writes to the disk cache
Returns
Promise<void>
set()
set(
key,
val,
options?): CacheDefined in: index.ts:244
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
| Parameter | Type |
|---|---|
key | string |
val | Buffer |
options? | SetOptions<string, Buffer<ArrayBufferLike>, CacheFetchContext> & object |
Returns
Overrides
LRUCache.setwalk()
walk(): AsyncGenerator<[string, Buffer<ArrayBufferLike>], void, unknown>Defined in: index.ts:142
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<ArrayBufferLike>], void, unknown>
walkSync()
walkSync(): Generator<[string, Buffer<ArrayBufferLike>], void, unknown>Defined in: index.ts:172
Synchronous form of Cache.walk()
Returns
Generator<[string, Buffer<ArrayBufferLike>], void, unknown>
Type Aliases
BooleanOrVoid
type BooleanOrVoid = boolean | void;Defined in: index.ts:57
CacheFetchContext
type CacheFetchContext =
| {
integrity: Integrity;
}
| undefined;Defined in: index.ts:20
CacheOptions
type CacheOptions = { [k in keyof LRUCache.Options<string, Buffer, CacheFetchContext>]?: LRUCache.Options<string, Buffer, CacheFetchContext>[k] } & object;Defined in: index.ts:26
Type declaration
| Name | Type | Description |
|---|---|---|
fetchMethod? | undefined | fetchMethod may not be provided, because this cache forces its own read-from-disk as the fetchMethod |
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. |
onDiskWrite? | (path, key, data) => any | called whenever an item is written to disk. |
path | string | folder where items should be stored to disk |
store? | string | global store root. Deleting an entry from disk with its integrity also removes the store entry, sidecar index and copied marker for that integrity. |