-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcacheManager.js
More file actions
62 lines (45 loc) · 1.71 KB
/
cacheManager.js
File metadata and controls
62 lines (45 loc) · 1.71 KB
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
53
54
55
56
57
58
59
60
61
62
require('@ostro/support/helpers')
const InvalidArgumentException = require('@ostro/support/exceptions/invalidArgumentException')
const CacheAdapter = require('./cacheAdapter')
const Manager = require('@ostro/support/manager')
class CacheManager extends Manager {
$type = 'cache';
store(name = null) {
return this.driver(name)
}
resolve(name) {
let $config = this.getStoreConfig(name);
if (!($config)) {
throw new InvalidArgumentException(`Cache store [${name}] is not defined.`);
}
return super.resolve(name, $config)
}
createMemoryDriver($config) {
return this.adapt(new(require('./adapter/memory'))($config));
}
createRedisDriver($config) {
return this.adapt(new(require('./adapter/redis'))(new(require('./client/redis'))($config), $config, this.getPrefix()));
}
createMemcachedDriver($config) {
return this.adapt(new(require('./adapter/memcached'))(new(require('./client/memcached'))($config), $config, this.getPrefix()));
}
createNullDriver($config) {
return this.adapt(new(require('./adapter/null'))($config));
}
createFileDriver($config) {
return this.adapt(new(require('./adapter/file'))($config['path'], $config, this.getPrefix()))
}
createDatabaseDriver($config) {
return this.adapt(new(require('./adapter/database'))($config['table'], this.$container.database))
}
adapt($cache) {
return new CacheAdapter($cache, this.$config.get(`${this.$type}.enabled`));
}
getPrefix() {
return super.getConfig(`prefix`);
}
getStoreConfig(name) {
return this.getConfig(`stores.${name}`);
}
}
module.exports = CacheManager