sf-filecache
Simple and smart FS based cache system.
sf-filecache
exists for two purposes:
- having a streameable fs based cache system
- opening only one file descriptor for cache queries
Usage
Buffer based:
var FileCache = ; var filecache = ; var endOfLife = Date + 36000; // Set a value in the filecache for the 'plop' keyfileCache;
Stream based:
var FileCache = ; var filecache = ; var endOfLife = Date + 36000; // Set a stream content in the filecache for the 'plop' keyfileCache;
API
FileCache(options)
FileCache constructor
Kind: global function
Api: public
Param | Type | Description |
---|---|---|
options | Object |
Options of the cache (dir, domain and clock) |
- FileCache(options)
- ._keyToPath(key) ⇒
String
- ._createHeader(header) ⇒
Buffer
- ._readHeader(data) ⇒
Object
- .get(key, cb) ⇒
void
- .getStream(key, cb) ⇒
void
- .set(key, data, eol, cb) ⇒
void
- .setStream(key, stream, eol, cb) ⇒
void
- .setEOL(key, eol, cb) ⇒
void
- ._keyToPath(key) ⇒
String
fileCache._keyToPath(key) ⇒ Transform a key into a path were to save/read the contents
Kind: instance method of FileCache
Returns: String
- The computed path
Api: private
Param | Type | Description |
---|---|---|
key | String |
The key to transform |
Buffer
fileCache._createHeader(header) ⇒ Create a bucket header
Kind: instance method of FileCache
Returns: Buffer
- The header contents as a buffer
Api: private
Param | Type | Description |
---|---|---|
header | Object |
Header description |
Object
fileCache._readHeader(data) ⇒ Read the header description from a buffer
Kind: instance method of FileCache
Returns: Object
- The header description
Param | Type | Description |
---|---|---|
data | Buffer |
The buffer |
void
fileCache.get(key, cb) ⇒ Get cached data for the given key
Kind: instance method of FileCache
Param | Type | Description |
---|---|---|
key | String |
The key |
cb | function |
The callback ( signature function(err:Error, data:Buffer) {}) |
void
fileCache.getStream(key, cb) ⇒ Get cached data as a stream for the given key
Kind: instance method of FileCache
Param | Type | Description |
---|---|---|
key | String |
The key |
cb | function |
The callback ( signature function(err:Error, stream:ReadableStream) {}) |
void
fileCache.set(key, data, eol, cb) ⇒ Set cached data at the given key
Kind: instance method of FileCache
Param | Type | Description |
---|---|---|
key | String |
The key |
data | Buffer |
The data to store |
eol | Number |
The resource invalidity timestamp |
cb | function |
The callback ( signature function(err:Error) {}) |
void
fileCache.setStream(key, stream, eol, cb) ⇒ Set cached data via a stream at the given key
Kind: instance method of FileCache
Param | Type | Description |
---|---|---|
key | String |
The key |
stream | ReadableStream |
The data to store as a readable stream |
eol | Number |
The resource invalidity timestamp |
cb | function |
The callback ( signature function(err:Error) {}) |
void
fileCache.setEOL(key, eol, cb) ⇒ Set end of life to the given key
Kind: instance method of FileCache
Param | Type | Description |
---|---|---|
key | String |
The key |
eol | Number |
The resource invalidity timestamp |
cb | function |
The callback ( signature function(err:Error) {}) |