# global-cache

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

Latest version **1.2.1** (published 2017-07-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install global-cache
pnpm add global-cache
yarn add global-cache
bun add global-cache
```

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2017-07-20 |
| First published | 2015-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/global-cache) |
| Module format | CommonJS |
| Node | >= 0.4 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | global, window, self, cache, global object |

## Links

- npm: https://www.npmjs.com/package/global-cache
- Repository: https://github.com/ljharb/global-cache
- Homepage: https://github.com/ljharb/global-cache#readme
- Issues: https://github.com/ljharb/global-cache/issues
- npm.io page: https://npm.io/package/global-cache

## Dependencies (2)

- [is-symbol](https://npm.io/package/is-symbol.md) ^1.0.1
- [define-properties](https://npm.io/package/define-properties.md) ^1.1.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2017-07-20
- 1.2.0 — 2016-04-06
- 1.1.0 — 2016-01-30
- 1.0.3 — 2015-10-20
- 1.0.2 — 2015-10-14
- 1.0.1 — 2015-08-12
- 1.0.0 — 2015-07-02

## README

# global-cache <sup>[![Version Badge][2]][1]</sup>

[![Build Status][3]][4]
[![dependency status][5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][11]][1]

[![browser support][9]][10]

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

```js
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`

[1]: https://npmjs.org/package/global-cache
[2]: http://versionbadg.es/ljharb/global-cache.svg
[3]: https://travis-ci.org/ljharb/global-cache.svg
[4]: https://travis-ci.org/ljharb/global-cache
[5]: https://david-dm.org/ljharb/global-cache.svg
[6]: https://david-dm.org/ljharb/global-cache
[7]: https://david-dm.org/ljharb/global-cache/dev-status.svg
[8]: https://david-dm.org/ljharb/global-cache#info=devDependencies
[9]: https://ci.testling.com/ljharb/global-cache.png
[10]: https://ci.testling.com/ljharb/global-cache
[11]: https://nodei.co/npm/global-cache.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/global-cache.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/global-cache.svg
[downloads-url]: http://npm-stat.com/charts.html?package=global-cache

---
_Source: https://npm.io/package/global-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
