
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
hot-file-cache
Advanced tools
A watched file cache which will invalidate automatically if the source changes
A file/glob cache which will invalidate automatically if the source changes (powered by chokidar)
Install the plugin with npm:
$ npm install --save-dev hot-file-cache
var hfc = new HotFileCache('*.md', {cwd: dir});
hfc.readFile('README.md').then(function(content) {
console.log(content);
});
var hfc = new HotFileCache('*.json', {
cwd: dir,
// the fileProcessor will be executed only once per file
fileProcessor: function (filename, fileContent) {
// the return value could also be a promise
return JSON.parse(fileContent);
}
});
hfc.readFile('demo.json').then(function(content) {
console.log(content);
});
You can pass all chokidar options.
Additionally you can pass the following options:
hot
(true|false) - Default: true - Wether to watch for changes or notuseCache
(true|false) - Default: true - Wether to cache the disk operationsfileProcessor
: (function) - Optional - Allow to process the file contents before they are written into the cache.Because of the asynchronous nature of disk operations all functions return a Promise
.
hfc.getFiles()
getFiles returns an array of all absolute filenames matching the pattern. As it looks into a warm cache it doesn't need any disk operations.
hfc.fileExists(absolutePath)
fileExists returns true if the given file exists.
As it looks in into a warm cache it doesn't need any disk operations.
hfc.readFile(absolutePath)
readFile returns the content of the given file.
If a file processor is passed the content is also processed.
The processed result is cached until chokidar
detects a file change on the disk.
hfc.close()
close will stop the file watching
hfc.on(eventName, callback);
all
Similar to the chokidar all event: (add
, addDir
, change
, unlink
or unlinkDir
)add
File has been addedaddDir
Directory has been addedchange
File has been changedunlink
File has been removedunlinkDir
Directory has been removedrevoke-cache
File was already hot-cached but has been changed or was removedvar hfc = new HotFileCache('*.json', {
cwd: dir,
fileProcessor: function process (filename, fileContent) {
return JSON.parse(fileContent);
}
});
hfc.readFile('demo.json') // 1
.then(function(content) {
console.log(content);
});
hfc.readFile('demo.json') // 2
.then(function(content) {
console.log(content);
});
hfc.readFile('demo.json') // 3
.then(function(content) {
console.log(content);
});
hfc.readFile('demo.json') // 4
.then(function(content) {
console.log(content);
});
Chokidar has a lot of of performance optimisations
Take a look at the CHANGELOG.md.
You're free to contribute to this project by submitting issues and/or pull requests. This project is test-driven, so keep in mind that every change and new feature should be covered by tests. This project uses the semistandard code style.
This project is licensed under MIT.
1.1.0
FAQs
A watched file cache which will invalidate automatically if the source changes
We found that hot-file-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.