1 | <?php |
||
14 | class UberMemcached implements ResourceInterface, UberStorageInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var Memcached $memcached |
||
18 | */ |
||
19 | private $memcached; |
||
20 | |||
21 | /** |
||
22 | * @param Memcached $memcached |
||
23 | */ |
||
24 | public function __construct(Memcached $memcached) |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function __toString() |
||
36 | |||
37 | /** |
||
38 | * @return Memcached |
||
39 | */ |
||
40 | public function getMemcached() |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | public function setConnection($host, $port) |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function addItem($key, $value, $expiration = null) |
||
57 | { |
||
58 | if ($expiration === null) { |
||
59 | $expiration = 60 * 60 * 24 * 30; // default expires after 30 days |
||
60 | } |
||
61 | |||
62 | return $this->getMemcached()->set($key, $value, $expiration); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | public function getItem($key) |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function getAllKeys() |
||
77 | { |
||
78 | $allKeys = $this->getMemcached()->getAllKeys(); |
||
79 | $locales = array(); |
||
80 | foreach ($allKeys as $key) { |
||
81 | if (!preg_match('/^[a-z]{2}_[a-zA-Z]{2}$|[a-z]{2}/', $key)) { |
||
82 | continue; |
||
83 | } |
||
84 | $locales[] = $key; |
||
85 | } |
||
86 | |||
87 | return $locales; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function deleteItem($key) |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function dropCache() |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | public function isFresh($timestamp) |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function getResource() |
||
119 | } |
||
120 |