-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cache.php
50 lines (41 loc) · 1.06 KB
/
Cache.php
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
<?php
/**
* @author
* @license MIT
*/
namespace fate\cache;
use Fate;
use fate\ioc\ServiceLocator;
use fate\core\InvalidConfigException;
use fate\core\FileNotFoundException;
/**
* 缓存
*/
final class Cache {
/**
* 实例
*/
private static $serviceLocator = null;
/**
* 获取缓存实例
*
* @param string $type
* @return mixed
*/
public static function getCache($type) {
if(!isset(Fate::$app->cache) || !isset(Fate::$app->cache[$type])) {
throw new InvalidConfigException('The cache configuration is not found');
}
if(null === Cache::$serviceLocator) {
Cache::$serviceLocator = new ServiceLocator();
}
if( !Cache::$serviceLocator->hasService($type) ){
Cache::$serviceLocator->setService(
$type,
Fate::createObjectAsDefinition(Fate::$app->cache[$type], null)
);
Cache::$serviceLocator->getService($type)->init();
}
return Cache::$serviceLocator->getService($type);
}
}