1.0.0 • Published 11 years ago
phialcash v1.0.0
phialcash
Simple in-memory file cache.
Installation
npm install phialcash
Example
var co = require('co');
var fs = require('mz/fs'); // or any generator friendly file system library
var config = {
fsLibrary: fs,
fsExistsMethod: 'exists',
fsReadFileMethod: 'readFile'
};
var fc = require('phialcash');
fc = new fc(config);
var filePath = './tests/file.fixture.txt';
var fileName = 'file.fixture.txt';
co(function* () {
yield fc.cache(filePath, fileName); // Caches file at filePath.
if (fc.has(fileName)) { // Checks if there is a cached version of the file.
yield fc.get(fileName); // Returns the cached version of the file.
}
fc.has(fileName); // true.
fc.clear(); // Empties the cache.
fc.has(fileName); // false.
})();API
new fc(config)
phialcash expects a generator friendly file system library.
config.fsLibrary- Reference to the file system libraryconfig.fsExistsMethod- String representation of the method name that checks if a file existsconfig.fsReadFileMethod- String representation of the method name that reads a file
fc.cache(filePath, fileName)
Caches the file at filePath. filePath, and fileName are string.
fc.has(fileName)
Returns true if there is a cached version of fileName; otherwise, returns false. fileName must be a file name string.
fc.get(fileName)
Returns the fileName's contents from memory. fileName must be a file name string.
fc.clear()
Clears the cache.
1.0.0
11 years ago