Skip to content

Latest commit

 

History

History
222 lines (102 loc) · 3.06 KB

faastjs.persistentcache.md

File metadata and controls

222 lines (102 loc) · 3.06 KB
id title hide_title
faastjs.persistentcache
PersistentCache class
true

faastjs > PersistentCache

PersistentCache class

A simple persistent key-value store. Used to implement Limits.cache for throttle().

Signature:

export declare class PersistentCache 

Remarks

Entries can be expired, but are not actually deleted individually. The entire cache can be deleted at once. Hence this cache is useful for storing results that are expensive to compute but do not change too often (e.g. the node_modules folder from an 'npm install' where 'package.json' is not expected to change too often).

By default faast.js will use the directory ~/.faastjs as a local cache to store data such as pricing retrieved from cloud APIs, and garbage collection information. This directory can be safely deleted if no faast.js instances are running.

Constructors

Constructor

Modifiers

Description

(constructor)(dirRelativeToHomeDir, expiration)

Construct a new persistent cache, typically used with Limits as part of the arguments to throttle().

Properties

Property

Modifiers

Type

Description

dir

readonly

string

The directory on disk where cached values are stored.

dirRelativeToHomeDir

readonly

string

The directory under the user's home directory that will be used to store cached values. The directory will be created if it doesn't exist.

expiration

readonly

number

The age (in ms) after which a cached entry is invalid. Default: 24*3600*1000 (1 day).

Methods

Method

Modifiers

Description

clear({ leaveEmptyDir })

Deletes all cached entries from disk.

entries()

Retrieve all keys stored in the cache, including expired entries.

get(key)

Retrieves the value previously set for the given key, or undefined if the key is not found.

set(key, value)

Set the cache key to the given value.