1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* This file is part of Phpfastcache. |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. |
10
|
|
|
* |
11
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
12
|
|
|
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types=1); |
16
|
|
|
|
17
|
|
|
namespace Phpfastcache\Drivers\Wincache; |
18
|
|
|
|
19
|
|
|
use DateTime; |
20
|
|
|
use Phpfastcache\Cluster\AggregatablePoolInterface; |
21
|
|
|
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; |
22
|
|
|
use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait; |
23
|
|
|
use Phpfastcache\Core\Item\ExtendedCacheItemInterface; |
24
|
|
|
use Phpfastcache\Entities\DriverStatistic; |
25
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; |
26
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheLogicException; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @deprecated will be removed as of v10 due to the lack of updates to PHP8 as officially stated by PHP: https://www.php.net/manual/en/install.windows.recommended.php |
30
|
|
|
* @method Config getConfig() |
31
|
|
|
*/ |
32
|
|
|
class Driver implements AggregatablePoolInterface |
33
|
|
|
{ |
34
|
|
|
use TaggableCacheItemPoolTrait; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function driverCheck(): bool |
40
|
|
|
{ |
41
|
|
|
return extension_loaded('wincache') && function_exists('wincache_ucache_set'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getHelp(): string |
45
|
|
|
{ |
46
|
|
|
return <<<HELP |
47
|
|
|
Wincache PECL extension is not maintained anymore and has been superseded. Check sourceforge for more informations: https://sourceforge.net/projects/wincache/' |
48
|
|
|
HELP; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return DriverStatistic |
53
|
|
|
*/ |
54
|
|
|
public function getStats(): DriverStatistic |
55
|
|
|
{ |
56
|
|
|
$memInfo = wincache_ucache_meminfo(); |
57
|
|
|
$info = wincache_ucache_info(); |
58
|
|
|
$date = (new DateTime())->setTimestamp(time() - $info['total_cache_uptime']); |
59
|
|
|
|
60
|
|
|
return (new DriverStatistic()) |
61
|
|
|
->setInfo(sprintf("The Wincache daemon is up since %s.\n For more information see RawData.", $date->format(DATE_RFC2822))) |
62
|
|
|
->setSize($memInfo['memory_free'] - $memInfo['memory_total']) |
63
|
|
|
->setData(implode(', ', array_keys($this->itemInstances))) |
64
|
|
|
->setRawData($memInfo); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
protected function driverConnect(): bool |
71
|
|
|
{ |
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param ExtendedCacheItemInterface $item |
77
|
|
|
* @return ?array<string, mixed> |
78
|
|
|
*/ |
79
|
|
|
protected function driverRead(ExtendedCacheItemInterface $item): ?array |
80
|
|
|
{ |
81
|
|
|
$val = wincache_ucache_get($item->getKey(), $suc); |
82
|
|
|
|
83
|
|
|
if ($suc === false || empty($val)) { |
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $val; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param ExtendedCacheItemInterface $item |
92
|
|
|
* @return mixed |
93
|
|
|
* @throws PhpfastcacheInvalidArgumentException |
94
|
|
|
* @throws PhpfastcacheLogicException |
95
|
|
|
*/ |
96
|
|
|
protected function driverWrite(ExtendedCacheItemInterface $item): bool |
97
|
|
|
{ |
98
|
|
|
|
99
|
|
|
return wincache_ucache_set($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $key |
104
|
|
|
* @param string $encodedKey |
105
|
|
|
* @return bool |
106
|
|
|
*/ |
107
|
|
|
protected function driverDelete(string $key, string $encodedKey): bool |
108
|
|
|
{ |
109
|
|
|
return wincache_ucache_delete($key); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
protected function driverClear(): bool |
116
|
|
|
{ |
117
|
|
|
return wincache_ucache_clear(); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|