file-data-cache
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

file-data-cache

Tiny util to cache data from files. Use case: a small amount of files need to be watched

const loadFileData = (filePath, fileContent) => {
    const result = ..... // Do something
    return result // This value will be cached
}

const fileCache = new FileDataCache({
  loadFileData,
  checkInterval: 60000,
  readFile: true
})

// 1. Initial load of data
let processedData = fileCache.loadData(SOME_FILE_PATH)

// 2. Second call to `loadData`
// Cached values will be returned if:
// A/ the ellapsed time between this call and the last time the file was loading is smaller than `checkInterval`
// B/ the last modified date of the file hasn't changed

processedData = fileCache.loadData(SOME_FILE_PATH)

Readme

Keywords

none

Package Sidebar

Install

npm i file-data-cache

Weekly Downloads

1

Version

2.1.1

License

MIT

Unpacked Size

20.7 kB

Total Files

9

Last publish

Collaborators

  • matthizou