Node.js implementation of iron.io's caching.
Node.js implementation of Iron's IronCache product.
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
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 = ironcachecreateClient 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 = ironcachecreateClient;
These methods are used to manage your caches. Create a new cache by putting a cache key/value pair to the cache.
Empty or nonexistent caches will return an empty array.
clientlistif err throw err;console.logres;;
"project_id": "PROJECT ID""name": "CACHE NAME""project_id": "PROJECT ID""name": "CACHE NAME"
Get information about a cache.
client.info'my-cache'if err throw err;console.logres;;
"size": "cache size"
Clear all items in a cache.
clientclearCache'my-cache'if err throw err;console.logres;;
Delete a cache and all items in it.
clientdelCache'my-cache'if err throw err;console.logres;;
CRUD the values stored in your caches.
Puts an item into a cache.
clientput'my-cache' 'key' value: 'some data'if err throw err;console.logres;;
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.
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.
clientincr'my-cache' 'key' 1if err throw err;console.logres;;
"msg": "Added""value": 132
Retrieve an item from the cache.
clientget'my-cache' 'key'if err throw err;console.logres;;
"cache": "CACHE NAME""key": "ITEM KEY""value": "ITEM VALUE""cas": "12345"
Delete an item from the cache.
clientdel'my-cache' 'key'if err throw err;console.logres;;
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.