1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Common\Cache; |
4
|
|
|
|
5
|
|
|
use Couchbase; |
6
|
|
|
use function explode; |
7
|
|
|
use function time; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Couchbase cache provider. |
11
|
|
|
* |
12
|
|
|
* @deprecated Couchbase SDK 1.x is now deprecated. Use \Doctrine\Common\Cache\CouchbaseBucketCache instead. |
13
|
|
|
* https://developer.couchbase.com/documentation/server/current/sdk/php/compatibility-versions-features.html |
14
|
|
|
* |
15
|
|
|
* @link www.doctrine-project.org |
16
|
|
|
*/ |
17
|
|
|
class CouchbaseCache extends CacheProvider |
18
|
|
|
{ |
19
|
|
|
/** @var Couchbase|null */ |
20
|
|
|
private $couchbase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Sets the Couchbase instance to use. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function setCouchbase(Couchbase $couchbase) |
28
|
|
|
{ |
29
|
|
|
$this->couchbase = $couchbase; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Gets the Couchbase instance used by the cache. |
34
|
|
|
* |
35
|
|
|
* @return Couchbase|null |
36
|
|
|
*/ |
37
|
|
|
public function getCouchbase() |
38
|
|
|
{ |
39
|
|
|
return $this->couchbase; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
protected function doFetch($id) |
46
|
|
|
{ |
47
|
|
|
return $this->couchbase->get($id) ?: false; |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
protected function doContains($id) |
54
|
|
|
{ |
55
|
|
|
return $this->couchbase->get($id) !== null; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
protected function doSave($id, $data, $lifeTime = 0) |
62
|
|
|
{ |
63
|
|
|
if ($lifeTime > 30 * 24 * 3600) { |
64
|
|
|
$lifeTime = time() + $lifeTime; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $this->couchbase->set($id, $data, (int) $lifeTime); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
protected function doDelete($id) |
74
|
|
|
{ |
75
|
|
|
return $this->couchbase->delete($id); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
protected function doFlush() |
82
|
|
|
{ |
83
|
|
|
return $this->couchbase->flush(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
protected function doGetStats() |
90
|
|
|
{ |
91
|
|
|
$stats = $this->couchbase->getStats(); |
92
|
|
|
$servers = $this->couchbase->getServers(); |
93
|
|
|
$server = explode(':', $servers[0]); |
94
|
|
|
$key = $server[0] . ':11210'; |
95
|
|
|
$stats = $stats[$key]; |
96
|
|
|
|
97
|
|
|
return [ |
98
|
|
|
Cache::STATS_HITS => $stats['get_hits'], |
99
|
|
|
Cache::STATS_MISSES => $stats['get_misses'], |
100
|
|
|
Cache::STATS_UPTIME => $stats['uptime'], |
101
|
|
|
Cache::STATS_MEMORY_USAGE => $stats['bytes'], |
102
|
|
|
Cache::STATS_MEMORY_AVAILABLE => $stats['limit_maxbytes'], |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.