cachefn

1.0.3 • Public • Published

cachefn

Decorate async (Promise.returning) functions with an expiring cache so costly operations don't need to be run all the time.

API

cachedFunction(func, timeout = Infinity, thisArg = undefined)

Returns a CachedFunction that will call func once until the cache expires. timeout is the timeout in milliseconds until the cache expires. the function will be called with thisArg as its this argument.

CachedFunction()

Returns a promise with the last value returned by the original function, unless the cache has expired, in which case it calls the function and returns a promise to the result.

CachedFunction#exec()

Run the original function, ignoring any cache. Calling it will store the result on the cache, overriding any previous result and timeout.

CachedFunction#clear()

Clear the cache. The next time the function is run, it will call the original function no matter what.

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i cachefn

    Weekly Downloads

    0

    Version

    1.0.3

    License

    MIT

    Last publish

    Collaborators

    • darkhogg