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

global-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

global-cache

Sometimes you have to do horrible things, like use the global object to share a singleton. Abstract that away, with this!

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
384K
decreased by-4.12%
Maintainers
1
Weekly downloads
 
Created
Source

global-cache Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

Sometimes you have to do horrible things, like use the global object to share a singleton. Abstract that away, with this!

This attaches a cache to the global object. It attempts to make it as undiscoverable as possible:

  • uses Symbols if available
  • if not, uses a string key that is not a valid identifier, so as not to show up in dot-notation browser autocomplete
  • makes it non-enumerable if property descriptors are supported

Keys are required to be strings or symbols.

Example

var cache = require('global-cache');
var assert = require('assert');

var value = {};
assert(cache.get(key) === undefined);
assert(cache.has(key) === false);

cache.set(key, value);
assert(cache.get(key) === value);
assert(cache.has(key) === true);

cache.delete(key);
assert(cache.get(key) === undefined);
assert(cache.has(key) === false);

Tests

Simply clone the repo, npm install, and run npm test

Keywords

FAQs

Package last updated on 06 Apr 2016

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