2.0.1 • Published 4 years ago

@krisell/file-cache v2.0.1

Weekly downloads
6
License
MIT
Repository
-
Last release
4 years ago

File based cache for Node.js

This package provides a simple filesystem based caching layer for Node.js-applications.

Usage

import FileCache from '@krisell/file-cache'

const cache = new FileCache('/tmp')

cache.remember(key, ttl, () => {
  // Do whatever you want, and return a promise which resolves to the data you like to cache.
  // The data is kept in cache and this callback will not be executed again until the cache has expired.

  // If your data can be retreived synchronously, you still need to return a promise and
  // can do this using return Promise.resolve(data)

  // ttl is given in seconds
})

// Example
cache.remember('tts-token', 30, () => {
  return Promise.resolve('result-of-heavy-db-query-or-api-call')
}).then(data => console.log(data))

Example use cases

API-calls that require a call to issue a token that is valid for 10 minutes. Use this cache to only perform this request at most every 9 minutes.

2.0.1

4 years ago

2.0.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago