|
1
|
|
|
<?php |
|
2
|
|
|
namespace ByJG\Cache; |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
use ByJG\Cache\Engine\ArrayCacheEngine; |
|
6
|
|
|
use ByJG\Cache\Engine\FileSystemCacheEngine; |
|
7
|
|
|
use ByJG\Cache\Engine\MemcachedEngine; |
|
8
|
|
|
use ByJG\Cache\Engine\NoCacheEngine; |
|
9
|
|
|
use ByJG\Cache\Engine\RedisCacheEngine; |
|
10
|
|
|
use ByJG\Cache\Engine\SessionCacheEngine; |
|
11
|
|
|
use ByJG\Cache\Engine\ShmopCacheEngine; |
|
12
|
|
|
use ByJG\Cache\Psr\CachePool; |
|
13
|
|
|
|
|
14
|
|
|
class Factory |
|
15
|
|
|
{ |
|
16
|
|
|
public static function createNullPool() |
|
17
|
|
|
{ |
|
18
|
|
|
return new CachePool( |
|
19
|
|
|
new NoCacheEngine() |
|
20
|
|
|
); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public static function createSessionPool($prefix = null, $bufferSize = null) |
|
24
|
|
|
{ |
|
25
|
|
|
return new CachePool( |
|
26
|
|
|
new SessionCacheEngine($prefix), |
|
27
|
|
|
$bufferSize |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public static function createFilePool($prefix = null, $bufferSize = null, $logger = null) |
|
32
|
|
|
{ |
|
33
|
|
|
return new CachePool( |
|
34
|
|
|
new FileSystemCacheEngine($prefix, $logger), |
|
35
|
|
|
$bufferSize |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public static function createShmopPool($config = [], $bufferSize = null, $logger = null) |
|
40
|
|
|
{ |
|
41
|
|
|
return new CachePool( |
|
42
|
|
|
new ShmopCacheEngine($config, $logger), |
|
43
|
|
|
$bufferSize |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function createArrayPool($bufferSize = null, $logger = null) |
|
48
|
|
|
{ |
|
49
|
|
|
return new CachePool( |
|
50
|
|
|
new ArrayCacheEngine($logger), |
|
51
|
|
|
$bufferSize |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public static function createMemcachedPool($servers = null, $bufferSize = null, $logger = null) |
|
56
|
|
|
{ |
|
57
|
|
|
return new CachePool( |
|
58
|
|
|
new MemcachedEngine($servers, $logger), |
|
59
|
|
|
$bufferSize |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public static function createRedisCacheEngine($servers = null, $password = null, $bufferSize = null, $logger = null) |
|
64
|
|
|
{ |
|
65
|
|
|
return new CachePool( |
|
66
|
|
|
new RedisCacheEngine($servers, $password, $logger), |
|
67
|
|
|
$bufferSize |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|