https://github.com/logzio/file-cacher
File system and mem-cache for files
https://github.com/logzio/file-cacher
Last synced: about 2 months ago
JSON representation
File system and mem-cache for files
- Host: GitHub
- URL: https://github.com/logzio/file-cacher
- Owner: logzio
- License: apache-2.0
- Created: 2020-11-24T14:51:34.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-04T11:01:09.000Z (about 3 years ago)
- Last Synced: 2025-04-17T00:21:02.937Z (2 months ago)
- Language: JavaScript
- Size: 82 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```js
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);
}getBundleFile()
.then(file => {
console.log(file);
})```