Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

age-cache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

age-cache

string map with ttl

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

Age Cache

A simple string map with a time to live. Similar to the maxAge setting in lru-cache except getting a key does not update it's time to live. Keys are not proactivly removed but only on calls to get or has.

API

new Cache(ttl, [strict = false])

Constructor, takes 2 arguments

  • ttl: time to live in milliseconds, mandatory
  • strict: whether it should be in strict mode which causes gets and deletes of non existent keys to throw, default is false.

cache.set(key, value)

Set the key to the specified value overwriting it if it already exists

cache.get(key)

Return the value with the specified key, if the key is not found then it will return undefined or in strict mode throw an error. The key will be deleted if it has expired.

cache.has(key)

Returns true if the key exists, false otherwise, if the key is expired it will be deleted and this method will return false.

cache.delete(key)

Remove the key from the cache. If the key exists returns true, if it does it returns false or, in strict mode, throws an error.

Usage

var Cache = require('age-cache');

var cache = new Cache(1000); // one second

cache.set('foo', 'bar');

cache.get('foo'); // bar

cache.has('foo'); // true

cache.has('bar'); // false

setTimeout(function () {
  cache.get('foo'); // undefined

  cache.has('foo'); // false
}, 1001)

FAQs

Package last updated on 17 Apr 2015

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