Socket
Socket
Sign inDemoInstall

frescas

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frescas

Self refreshable in-memory data cache


Version published
Maintainers
1
Created
Source

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:

  • FreshValue & unit tests.
  • FreshValueMap & unit tests.

Keywords

FAQs

Package last updated on 12 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc