1 | 'use strict';
|
2 |
|
3 | function makeCache() {
|
4 |
|
5 | var cache = Object.create(null);
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | cache['foo'] = 1;
|
11 | delete cache['foo'];
|
12 |
|
13 | return cache;
|
14 | }
|
15 |
|
16 | module.exports = Cache;
|
17 | function Cache() {
|
18 | this._store = makeCache();
|
19 | }
|
20 |
|
21 | Cache.prototype.set = function(key, value) {
|
22 | return this._store[key] = value;
|
23 | };
|
24 |
|
25 | Cache.prototype.get = function(key) {
|
26 | return this._store[key];
|
27 | };
|
28 |
|
29 | Cache.prototype.has = function(key) {
|
30 | return key in this._store;
|
31 | };
|
32 |
|
33 | Cache.prototype.delete = function(key) {
|
34 | delete this._store[key];
|
35 | };
|
36 |
|
37 | Object.defineProperty(Cache.prototype, 'size', {
|
38 | get: function() {
|
39 | return Object.keys(this._store).length;
|
40 | }
|
41 | });
|