Thoroughfare
A really simple caching system insipred by ActiveSupport::Cache
Download
Releases are available for download from GitHub. Alternatively, you can install using Node Package Manager (npm):
npm install thoroughfare
Example
var thoroughfare = ; memory_store = ;memory_store;
Documentation
Standard Methods
Stores
Stores
<a name="memorystore"/ >
MemoryStore
Options
- prefix - The prefix to be prepended to every key in the store
RedisStore __Options__ * prefix - Prefix to be prepended to all keys in the store * host - The hostname of the redis server you'd like to use * port - The port that the redis server you want to use listens on * password - If the redis server requires authentication * database - Select the database that you'd like to use for storage * expire - The expiration time of all keys in the store in seconds (default 0)
Standard Methods ### store.read(key, callback)
Reads a key from the store and returns a value if found, otherwise returning null
Arguments
- key - A string key for which to search.
- callback(err, value) - A callback which returns if there's an error or passes the retrieved value
Example
store;
### store.write(key, value, callback)
Writes a value to the store for key
Arguments
- key - A key of type string
- value - data to be stored for the key. It will be JSON.stringified before being stored
- callback(err) - A callback to be called when the operation is complete.
Example
store
### store.fetch(key, generate, callback)
Similar to read except that Thoroughfare will execute the generate function if a null value is returned from the store and store the result under key
Arguments
- key - A key of type string
- generate(key) - A function that generates the desired result for the key
- callback(err, value) - A callback which returns with the value retrieved from the store or generated if it didn't exist
Example
var { return ;});store;
### store.remove(key, callback) Removes the value stored for given key from the store
Arguments
- key - A key of type string
- callback(err) - Callback called on successful deletion from the store
Example
store;
### store.exists(key, callback)
Checks the store for the existence of a value for given key and returns true / false as to its presence
Arguments
- key - key of type string
- callback(err, exists) - A callback that returns the existence of the given key
Example
store
### store.clear(callback)
Empties the store of all key/value pairs
Arguments
- callback(err) - A callback which is called after all the operation completes.
Example
storeclear { if err throw err; console;};