A very simple in memory file cache for node.js. It's a drop in replacement
for fs.readFile
and fs.readSyncFile
Files are cached LRU style in memory. By default inmemfilecache monitors the folders of files in the cache. If a file changes it's removed from the cache. This means you can use it in dev environments and not have to disable it while your server is running.
var Cache = require('inmemfilecache');
var cache = new Cache();
cache.readFile('/path/to/file', callback);
-
Cache(options)
options are optional
-
cacheSizeLimit
the number of bytes the cache can hold. Defaults to 64 meg.
-
checkForFileChanges
removes files from cache if the file changes. Default = true
-
-
Cache.readFile
See
fs.readFile
-
Cache.readFileSync
See
fs.readFileSync
-
Cache.setCacheLimit
Changes the cache's size limit. If it's over this limit things will be removed from the cache until it's under the limit.
-
Cache.clear
clears the cache and all folder trackers.
Your app will not exit as along as folders are being tracked. Call cache.clear
to clear all
folder trackers.