New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

thoroughfare

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thoroughfare

A really simple cache inspired by Ruby on Rails' ActiveSupport::Cache gem with Memory and Redis storage options.

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 = require('thoroughfare');

memory_store = thoroughfare('memory', {prefix: "test"});
memory_store.connect(function(err, store){
  if (err) throw err;
  store.write("key", "value", function(err){
    if (err) throw err;
    console.log("Set key to value");
  });
});

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.read('key', function(err, value) {
  // if there was a problem interacting with the backend store then err will contain that err
  console.log(value);
});

### 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.write('key', {name: "Patrick"}, function(err) {
  if (err) throw err; // Oh noes there was an error
})

### 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 generate = function(key, cb) {
  return cb(null, key + "-generated");
});
store.fetch(key, generate, function(err, value) {
  if (err) throw err;
  console.log(value);
});

### 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.remove('no-longer-needed', function(err){
  console.log("Successfully deleted key");
});

### 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.exists(key, function(err, exists) {
  if (err) throw err;
  console.log("I " + (exists ? "found" : "didn't find") the key");
});

### 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

store.clear(function(err) {
  if (err) throw err;
  console.log("Emptied the store");
});

Keywords

FAQs

Package last updated on 15 Apr 2013

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc