24 private const TAG =
'tag';
25 private const TIME =
'time';
31 parent::__construct ( $root,
$postfix );
32 $defaultParams = [
'servers' => [ [
'host' =>
'0.0.0.0',
'port' => 11211 ] ],
'serializer' => \Memcached::SERIALIZER_PHP,
'persistent' => true ];
33 $cacheParams = \array_merge ( $defaultParams, $cacheParams );
34 $this->cacheInstance = new \Memcached ( $cacheParams [
'persistent'] ? \crc32 ( $root ) : null );
35 if (isset ( $cacheParams [
'serializer'] )) {
36 $this->cacheInstance->setOption ( \Memcached::OPT_SERIALIZER, $cacheParams [
'serializer'] );
38 if ($this->cacheInstance->isPristine ()) {
39 $this->
addServers ( $cacheParams [
'servers'] );
43 public function addServer($host, $port, $weight =
null) {
44 $this->cacheInstance->addServer ( $host, $port, $weight );
45 $statuses = $this->cacheInstance->getStats ();
46 if (! isset ( $statuses [
"$host:$port"] )) {
47 throw new CacheException (
"Connection to the server $host:$port failed!" );
52 foreach ( $servers as $srv ) {
53 $this->
addServer ( $srv [
'host'] ??
'0.0.0.0', $srv [
'port'] ?? 11211, $srv [
'weight'] ??
null);
58 $this->cacheInstance->setOption ( \Memcached::OPT_SERIALIZER, $serializer );
69 $this->cacheInstance->get ( $k );
70 return \Memcached::RES_NOTFOUND !== $this->cacheInstance->getResultCode ();
73 public function store($key, $content, $tag =
null) {
74 $this->cacheInstance->set ( $this->
getRealKey ( $key ), [ self::CONTENT => $content,self::TAG => $tag,self::TIME => \time () ] );
78 return \crc32 ( $key );
88 $entry = $this->cacheInstance->get ( $this->
getRealKey ( $key ) );
110 return $this->cacheInstance->get ( $key ) [
self::TIME];
113 public function remove($key) {
115 $this->cacheInstance->delete ( $this->
getRealKey ( $key ) );
119 $this->cacheInstance->flush ();
124 $keys = $this->cacheInstance->getAllKeys ();
126 foreach ( $keys as $key ) {
127 $entry = $this->cacheInstance->get ( $key );
128 if ($entry [self::TAG] === $type) {
129 $result [] =
new CacheFile ( \ucfirst ( $type ), $key, $entry [self::TIME],
"", $key );
132 if (\count ( $result ) === 0)
133 $result [] =
new CacheFile ( \ucfirst ( $type ),
"",
"",
"" );
138 $keys = $this->cacheInstance->getAllKeys ();
139 foreach ( $keys as $key ) {
140 $entry = $this->cacheInstance->get ( $key );
141 if ($entry [self::TAG] === $type) {
142 $this->cacheInstance->delete ( $key );
148 return parent::getCacheInfo () .
"<br>Driver name : <b>" . \Memcached::class .
"</b>";
This class is responsible for storing Arrays in PHP files.
This class is responsible for storing values with MemCached.
file_get_contents($key)
return data stored for the given key.
addServers(array $servers)
fetch($key)
Fetches data stored for the given key.
clear()
Clears all cache entries.
setSerializer($serializer)
__construct($root, $postfix="", $cacheParams=[])
Initializes the cache-provider.
exists($key)
Check if annotation-data for the key has been stored.
addServer($host, $port, $weight=null)
store($key, $content, $tag=null)
Caches the given data with the given key.
getTimestamp($key)
Returns the timestamp of the last cache update for the given key.