New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

cacheable-data

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cacheable-data

Cache data in memory.

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

Cachable

Methods

cacheable(function => Promise) => (function CacheWrapper => Promise)

The cacheable library receives a function, lazily executes it, and caches the data resolved from the function. It returns a function that returns a Promise that resolves to the cached data.

CacheWrapper.refresh = () => Promise

CacheWrapper returned by cacheable method, contains the refresh method, which allows manual trigger to re-run user function and refresh cached data.

Usage

const cacheable = require('cacheable-data')

const cacheWrapper = cacheable(() => {
  // Your custom function to load the data
  // Should return a Promise that resolves to the data to cache
})

// Will only run the custom function once, and return cached data subsequently.
const cachedData = await cacheWrapper()

// Will refresh internal cache.
const refreshedData = await cacheWrapper.refresh()

Example

const cacheable = require('cacheable-data')

const cacheWrapper = cacheable(async () => Date.now())

;(async () => {
  console.log(await cacheWrapper()) // 1522628133629

  console.log(await cacheWrapper()) // 1522628133629

  console.log(await cacheWrapper.refresh()) // 1522628175880

  console.log(await cacheWrapper()) // 1522628175880
})()

FAQs

Package last updated on 17 Apr 2018

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