Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 856 Bytes

README.md

File metadata and controls

26 lines (19 loc) · 856 Bytes

idmp/node-fs

Usage

import idmp from 'idmp'
import fsWrap, { cacheDir, getCachePath } from 'idmp/node-fs'
const fsIdmp = fsWrap(idmp)

await fsIdmp(
  'localFileSystemCache',
  async () => {
    return await getData(...)
  },
  { maxAge: 60 * 1000 }
)

Cache data will be stored in the cacheDir temporary directory and follow the same cache options as idmp. If the data is in the memory, it is read from the memory first. If it is not in the memory, it is read from the file system. If the cache validity period expires, it will be read from the remote end.

Notice

  • Data persistence only supports string type globalKey and data structures that can be serialized by serialize-javascript
  • If return value is undefined it will not be cached, you must return null