global-cache

WebJar for global-cache

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

global-cache
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

global-cache
WebJar for global-cache
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/ljharb/global-cache

Download global-cache

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/global-cache/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>global-cache</artifactId>
    <version>1.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/global-cache/
implementation 'org.webjars.npm:global-cache:1.2.1'
// https://jarcasting.com/artifacts/org.webjars.npm/global-cache/
implementation ("org.webjars.npm:global-cache:1.2.1")
'org.webjars.npm:global-cache:jar:1.2.1'
<dependency org="org.webjars.npm" name="global-cache" rev="1.2.1">
  <artifact name="global-cache" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='global-cache', version='1.2.1')
)
libraryDependencies += "org.webjars.npm" % "global-cache" % "1.2.1"
[org.webjars.npm/global-cache "1.2.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : define-properties jar [1.1.2,2)
org.webjars.npm : is-symbol jar [1.0.1,2)

Project Modules

There are no modules declared in this project.

global-cache Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

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

Versions

Version
1.2.1