forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseCache.js
More file actions
52 lines (38 loc) · 966 Bytes
/
Copy pathBaseCache.js
File metadata and controls
52 lines (38 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var CacheEntry = require('./CacheEntry');
var Events = require('./events');
var EventDispatcher = require('../events/EventDispatcher');
var BaseCache = function ()
{
this.entries = new Map();
this.events = new EventDispatcher();
};
BaseCache.prototype.constructor = BaseCache;
BaseCache.prototype = {
add: function (key, data)
{
this.entries.set(key, data);
this.events.dispatch(new Events.CACHE_ADD_EVENT(this, key, data));
},
has: function (key)
{
return this.entries.has(key);
},
get: function (key)
{
return this.entries.get(key);
},
remove: function (key)
{
var entry = this.get(key);
if (entry)
{
this.entries.delete(key);
this.events.dispatch(new Events.CACHE_REMOVE_EVENT(this, key, entry.data));
}
},
destroy: function ()
{
this.entries.clear();
}
};
module.exports = BaseCache;