vlt / docs

  • PricingBenchmarks (opens in new window)Community (opens in new window)Feedback
  • Overview
    • Overview
    • Reference
  • Classes
  • Cache
  • Type Aliases
  • BooleanOrVoid
  • CacheFetchContext
  • CacheOptions
  1. Client
  2. /
  3. API Reference
  4. /
  5. @vltpkg/cache
  6. /
  7. Reference

Reference

Classes

Cache

Defined in: index.ts:70

Extends

  • LRUCache<string, Buffer, CacheFetchContext>

Constructors

new Cache()
TypeScript
new Cache(options): Cache

Defined in: index.ts:99

Parameters
ParameterType
optionsCacheOptions
Returns

Cache

Overrides
TypeScript
LRUCache<
  string,
  Buffer,
  CacheFetchContext
>.constructor

Properties

PropertyTypeDefault valueOverrides
[toStringTag]string'@vltpkg/cache.Cache'LRUCache.[toStringTag]
onDiskDelete?(path: string, key: string, deleted: boolean) => anyundefined-
onDiskWrite?(path: string, key: string, data: Buffer) => anyundefined-
store?stringundefined-

Accessors

pending
Get Signature
TypeScript
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
TypeScript
get static defaultMax(): number

Defined in: index.ts:95

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

Returns

number

Methods

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

Defined in: index.ts:161

Returns

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

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

Defined in: index.ts:193

Returns

Generator<[string, Buffer<ArrayBufferLike>], void>

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

Defined 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
ParameterTypeDefault value
keystringundefined
fromDiskbooleanfalse
integrity?`sha512-${string}`undefined
Returns

boolean

Overrides
TypeScript
LRUCache.delete
fetchSync()
TypeScript
fetchSync(key, opts?): undefined | Buffer<ArrayBufferLike>

Defined in: index.ts:314

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

Parameters
ParameterType
keystring
opts?FetchOptions<string, Buffer<ArrayBufferLike>, CacheFetchContext>
Returns

undefined | Buffer<ArrayBufferLike>

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

Defined in: index.ts:298

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

Parameters
ParameterType
integrity?`sha512-${string}`
Returns

undefined | string

path()
TypeScript
path(key?): string

Defined in: index.ts:291

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

Parameters
ParameterType
key?string
Returns

string

promise()
TypeScript
promise(): Promise<void>

Defined in: index.ts:282

Resolves when there are no pending writes to the disk cache

Returns

Promise<void>

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

Defined 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
ParameterType
keystring
valBuffer
options?SetOptions<string, Buffer<ArrayBufferLike>, CacheFetchContext> & object
Returns

Cache

Overrides
TypeScript
LRUCache.set
walk()
TypeScript
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()
TypeScript
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

TypeScript
type BooleanOrVoid = boolean | void;

Defined in: index.ts:57


CacheFetchContext

TypeScript
type CacheFetchContext = 
  | {
  integrity: Integrity;
 }
  | undefined;

Defined in: index.ts:20


CacheOptions

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

Defined in: index.ts:26

Type declaration

NameTypeDescription
fetchMethod?undefinedfetchMethod may not be provided, because this cache forces its own read-from-disk as the fetchMethod
onDiskDelete?(path, key, deleted) => anycalled 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) => anycalled whenever an item is written to disk.
pathstringfolder where items should be stored to disk
store?stringglobal store root. Deleting an entry from disk with its integrity also removes the store entry, sidecar index and copied marker for that integrity.

Previous@vltpkg/cacheNext@vltpkg/cache-unzip

On this page

  • Classes
  • Cache
  • Type Aliases
  • BooleanOrVoid
  • CacheFetchContext
  • CacheOptions

Deploy your package on vlt.io

Publish scoped and private packages, manage organizations and access, and give every developer and CI environment a consistent source for public and private JavaScript dependencies.

Publish now