Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saidM/hoard.js
:post_office: Blazing fast in-memory caching library for Node.js
https://github.com/saidM/hoard.js
cache caching nodejs
Last synced: 11 days ago
JSON representation
:post_office: Blazing fast in-memory caching library for Node.js
- Host: GitHub
- URL: https://github.com/saidM/hoard.js
- Owner: saidM
- License: mit
- Created: 2017-10-20T23:58:57.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-21T00:40:12.000Z (about 7 years ago)
- Last Synced: 2024-09-15T05:39:46.007Z (about 2 months ago)
- Topics: cache, caching, nodejs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/hoard.js
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazingly-fast - hoard.js - :post_office: Blazing fast in-memory caching library for Node.js (JavaScript)
README
# hoard.js
[![Build Status](https://travis-ci.org/saidM/hoard.js.svg?branch=master)](https://travis-ci.org/saidM/hoard.js) [![Coverage Status](https://coveralls.io/repos/github/saidM/hoard.js/badge.svg)](https://coveralls.io/github/saidM/hoard.js) [![NPM Downloads](https://img.shields.io/npm/dt/hoard.js.svg)](https://www.npmjs.com/package/hoard.js) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/saidM/hoard.js) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/saidM/hoard.js)Blazing fast in-memory caching library for Node.js.
# Installation
$ npm install hoard.js
# UsageThe first step if to require the module:
```javascript
const cache = require('hoard.js')
```## cache.set(key, value, ttl = null)
Stores an item in the cache. You can specify the time to live (in seconds).
```javascript
// won't expire
cache.set('foo', 'bar')
.then(data => console.log(data)) // 'bar'// will expire in 60 seconds
cache.set('me', 'Hi this is me', 60)
.then(data => console.log(data)) // 'Hi this is me'
```## cache.get(key)
Retrieves an item from the cache. It resolves the promise if the item was found or rejects the promise if the item is not present in the cache or has expired.
```javascript
cache.get('foo')
.then(data => console.log(data)) // barcache.get('unknown')
.catch(err => console.error(err)) // ITEM_NOT_FOUND
```## cache.incr(key)
Increments the value of the given key. Will reject the promise if the value is not of `number` type.
```javascript
cache.set('age', 24)
.then(() => cache.incr('age'))
.then(data => console.log(data)) // 25cache.set('foo', 'bar')
.then(() => cache.incr('foo'))
.catch(err => console.error(err)) // ITEM_IS_NOT_A_NUMBER
```## cache.decr(key)
Decrements the value of the given key. Will reject the promise if the value is not of `number` type.
```javascript
cache.set('age', 24)
.then(() => cache.decr('age'))
.then(data => console.log(data)) // 23cache.set('foo', 'bar')
.then(() => cache.decr('foo'))
.catch(err => console.error(err)) // ITEM_IS_NOT_A_NUMBER
```## cache.del(key)
Deletes an item from the cache. If the item was successfully deleted, the promise resolves with the item value, otherwise it rejects the promise.
```javascript
cache.del('foo')
.then(data => console.log(data)) // 'bar'
```## cache.clear()
Deletes all items from the cache.
```javascript
cache.clear()
.then(() => console.log('Cache is now empty'))
```# Licence
MIT