Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
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
The npm package hot-file-cache receives a total of 4 weekly downloads. As such, hot-file-cache popularity was classified as not popular.
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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.