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

basiccache

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basiccache

An extremely basic cache with a simple expiry system

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

basiccache.js

An extremely basic cache with a simple expiry system

Installation

npm install basiccache

Usage

first

node

var BasicCache = require('basiccache');

html

<script src="basiccache.min.js"></script>
<!-- // defines BasicCache() -->

then

var cache = new BasicCache();

cache.set('key', 'value', 5 * 1000);
// key will expire in 5 seconds, regardless of access

cache.get('key');
// => 'value'

setTimeout(function() {
  cache.get('key');
  // => 'value'
}, 3 * 1000);

setTimeout(function() {
  cache.get('key');
  // => undefined
}, 6 * 1000);

expiry is set per individual key

Function

new BasicCache([opts])

  • opts.debug: a function to use to print debug messages, defaults to a noop
  • opts.prefix: string to prefix the cache keys with for the internal cache object, defaults to basiccache_
  • opts.purgeInterval: a time, in ms, to purge the cache of expired items, defaults to no timer`

cache.get(key)

returns the cached item if it exists and hasn't expired. If the item doesn't exist, or has been invalidated, this function will return undefined

cache.set(key, value, [expires])

set a key to a value, expires is the number of milliseconds from now when this specific cache entry expires, defaults to 5 * 60 * 1000 (5 minutes)

cache.remove(key)

remove an entry from the cache, no errors are thrown if the key doesn't exist or is already invalidated

cache.clear()

remove all entries from the cache

cache.purge()

remove expired items from the cache

cache.sleep()

clear the purgeInterval if it was set

License

MIT

Keywords

FAQs

Package last updated on 19 May 2014

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