file-cacher

1.0.0 • Public • Published

File Cacher

Description

This package will handle file caching for services in need for fast file access. In essence, it will cache common files in memory, while less common files will be accessed from file system.

Additionally, it will cache similar requests promises. meaning, if two request for downloading the same file are being sent paralleled, it will only generate one request.

Usage

 
const fileCacher = new FileCacher({
      tmpDir: './tmp',
      debug : true,
      maxFileSystemCacheSize: 1000, // in MB
      maxInMemoryCacheSize: 300, // in MB
});
 
 
const filesGroupIdentifier = 'assets'
 
function getBundleFile() {
    const fileName = 'dist/bundle.aa8w37vhr.js';
    const fileUrl = `https://app.logz.io/${fileName}`;
    const fileGetter = () => fetch(fileUrl, { compress: true });
    
    return fileCacher.get(filesGroupIdentifier, fileName, fileGetter); 
}
 
getFile()
    .then(file => {
        console.log(file);
    })
 

Readme

Keywords

Package Sidebar

Install

npm i file-cacher

Weekly Downloads

1,498

Version

1.0.0

License

none

Unpacked Size

29.7 kB

Total Files

13

Last publish

Collaborators

  • mikach