npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iron-cache

v0.3.0

Published

Node.js implementation of iron.io's caching.

Downloads

204

Readme

Iron-Cache NPM version Build Status

Node.js implementation of Iron's IronCache product.

Usage

Create an iron project. In your dashboard, click the credentials link (the little key) to see your Project ID and Token. These are required to use the IronCache API with this module.

Initialize the module using your Project ID and Token.

You can also add environment variables to your application to initialize the module. These variables are IRON_CACHE_PROJECT and IRON_CACHE_TOKEN. When using the environment variables, there is no need to pass the options object when creating the client object.

var ironcache = require('iron-cache');

// Pass an options object.
var client = ironcache.createClient({ project: 'project', token: 'token' });

// When using the environment variables IRON_CACHE_PROJECT & IRON_CACHE_TOKEN.
// This will throw an error if the environment variables are not set.
var client = ironcache.createClient();

The API usage is split into two pieces: cache management and key management.

Cache Management

These methods are used to manage your caches. Create a new cache by putting a cache key/value pair to the cache.

List Caches

Empty or nonexistent caches will return an empty array.

client.list(function(err, res) {
  if (err) throw err;
  console.log(res);
});

Response:

[
  {
    "project_id": "PROJECT ID",
    "name": "CACHE NAME"
  },
  {
    "project_id": "PROJECT ID",
    "name": "CACHE NAME"
  }
]

Cache Information

Get information about a cache.

client.info('my-cache', function(err, res) {
  if (err) throw err;
  console.log(res);
});

Response:

{
  "size": "cache size"
}

Clear Cache

Clear all items in a cache.

client.clearCache('my-cache', function(err, res) {
  if (err) throw err;
  console.log(res);
});

Response:

{
  "msg": "Cleared."
}

Delete Cache

Delete a cache and all items in it.

client.delCache('my-cache', function(err, res) {
  if (err) throw err;
  console.log(res);
});

Response:

{
  "msg": "Deleted."
}

Key Management

CRUD the values stored in your caches.

Put

Puts an item into a cache.

client.put('my-cache', 'key', { value: 'some data' }, function(err, res) {
  if (err) throw err;
  console.log(res);
});

Value is required and is the data that will be persisted in the key. Other available properties include the following.

  • expires_in: How long in seconds to keep the item in the cache before it is deleted. By default, items do not expire. Maximum is 2,592,000 seconds (30 days).
  • replace: If set to true, only set the item if the item is already in the cache. If the item is not in the cache, do not create it.
  • add: If set to true, only set the item if the item is not already in the cache. If the item is in the cache, do not overwrite it.
  • cas: If set, the new item will only be placed in the cache if there is an existing item with a matching key and cas value. An item’s cas value is automatically generated and is included when the item is retrieved.

Response:

{
  "msg": "Stored."
}

Increment

Increment an item's value. The amount must be a number and attempting to increment non-numeric values results in an error. Negative amounts may be passed to decrement the value. The increment is atomic, so concurrent increments will all be observed.

client.incr('my-cache', 'key', 1, function(err, res) {
  if (err) throw err;
  console.log(res);
});

Response:

{
  "msg": "Added",
  "value": 132
}

Get

Retrieve an item from the cache.

client.get('my-cache', 'key', function(err, res) {
  if (err) throw err;
  console.log(res);
});

Response:

{
  "cache": "CACHE NAME",
  "key": "ITEM KEY",
  "value": "ITEM VALUE",
  "cas": "12345"
}

Delete

Delete an item from the cache.

client.del('my-cache', 'key', function(err, res) {
  if (err) throw err;
  console.log(res);
});

Response:

{
  "msg": "Deleted."
}

License

The MIT License (MIT)

Copyright (c) 2014 Matt Hernandez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.