frescas
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

frescas

Self-refreshable in-memory data cache.

  • FreshValue and AsyncFreshValue - single refreshable value.
  • FreshValueMap and AsyncFreshValueMap - maps of refreshable values.

Usage example:

/** Create a refreshable value. Define `load` function and use correct `refreshPeriodMillis` interval. */
const currentAccessToken = new AsyncFreshValue({
        refreshPeriodMillis: 0,
        load: async (settings) => {
            const response = await fetchAccessToken(/*....*/);
            settings.refreshPeriodMillis = Date.now() - response.expirationTime;
            return response.token;
        }
    });

// Use the fresh value :

async function getA(): A {
    const accessToken: string = await currentAccessToken.get();
    return fetch(accessToken, /** A-call params.*/);
}

async function getB(): B {
    const accessToken: string = await currentAccessToken.get();
    return fetch(accessToken, /** B-call params.*/);
}

Docs & tests

Check in-code documentation and tests:

/frescas/

    Package Sidebar

    Install

    npm i frescas

    Weekly Downloads

    457

    Version

    0.9.0

    License

    Apache-2.0

    Unpacked Size

    25.1 kB

    Total Files

    15

    Last publish

    Collaborators

    • mfursov