-
Notifications
You must be signed in to change notification settings - Fork 50
/
HomeMaticCacheManager.js
executable file
·48 lines (40 loc) · 1.04 KB
/
HomeMaticCacheManager.js
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
// ToDo Time based cache
function HomeMaticCacheManager (log) {
this.log = log
this.log.debug('[Cache] initalizing')
this.clearAll()
}
HomeMaticCacheManager.prototype.clearAll = function () {
this.cache = {}
this.log.debug('[Cache] cleared')
}
HomeMaticCacheManager.prototype.doCache = function (address, value) {
// sanity check
var parts = address.split(':')
if (parts.length !== 2) {
return
}
parts = address.split('.')
if (parts.length !== 3) {
return
}
this.log.debug('[Cache] write %s for %s', value, address)
this.cache[address] = value
}
HomeMaticCacheManager.prototype.getValue = function (address) {
let cv = this.cache[address]
if (cv) {
this.log.debug('[Cache] hit on %s %s', address, cv)
return cv
} else {
this.log.debug('[Cache] fail on %s', address)
return undefined
}
}
HomeMaticCacheManager.prototype.deleteValue = function (address) {
this.log.debug('[Cache] remove %s', address)
delete this.cache[address]
}
module.exports = {
HomeMaticCacheManager: HomeMaticCacheManager
}