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

cache

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache

Simple caching object with optional TTL and file system persistence.

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.9K
decreased by-17.24%
Maintainers
1
Weekly downloads
 
Created
Source

Cache - A simple caching object with TTL

Copyright 2017 Sleepless Software Inc. All rights reserved.

Install

npm install cache

Usage

Cache = require("cache");

c = new Cache(10 * 1000);    // Create a cache with 10 second TTL

key = "foo";
val = "something";    // any object

c.put(key, val);      // put it in the cache.
                      // Optional 3rd arg is TTL for just this
					  // key, e.g.;  c.put(key, val, 5 * 1000);

c.get(key);           // "something" (less than 10 secs have passed)

// 11 seconds later ...
setTimeout(function() {

	c.get(key);       // expired out of cache

}, 11 * 1000);

More

You can also do some other stuff.

c.del(key)            // delete key/val before expiry

You can create a cache that will write its contents to a file in JSON form (not recommended for production purposes):

c = new Cache(10 * 1000, "data.json");

Now, when do anything that changes the contents of the cache, it will write it to the file "data.json":

c.put(key, val);		// data.json appears

Also, the cache will be preloaded from the file when you instantiate it, if the file is present.

FAQs

Package last updated on 26 Jun 2022

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