1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Cache Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Cache\Adapter; |
10
|
|
|
|
11
|
|
|
use Joomla\Cache\AbstractCacheItemPool; |
12
|
|
|
use Joomla\Cache\Item\HasExpirationDateInterface; |
13
|
|
|
use Joomla\Cache\Item\Item; |
14
|
|
|
use Psr\Cache\CacheItemInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* XCache cache driver for the Joomla Framework. |
18
|
|
|
* |
19
|
|
|
* @since 1.0 |
20
|
|
|
*/ |
21
|
|
|
class XCache extends AbstractCacheItemPool |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* This will wipe out the entire cache's keys |
25
|
|
|
* |
26
|
|
|
* @return boolean The result of the clear operation. |
27
|
|
|
* |
28
|
|
|
* @since 1.0 |
29
|
|
|
*/ |
30
|
|
|
public function clear() |
31
|
|
|
{ |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Method to get a storage entry value from a key. |
36
|
|
|
* |
37
|
|
|
* @param string $key The storage entry identifier. |
38
|
|
|
* |
39
|
|
|
* @return CacheItemInterface |
40
|
|
|
* |
41
|
|
|
* @since 1.0 |
42
|
|
|
*/ |
43
|
|
|
public function getItem($key) |
44
|
|
|
{ |
45
|
|
|
$item = new Item($key); |
46
|
|
|
|
47
|
|
|
if ($this->hasItem($key)) |
48
|
|
|
{ |
49
|
|
|
$item->set(xcache_get($key)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $item; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Method to remove a storage entry for a key. |
57
|
|
|
* |
58
|
|
|
* @param string $key The storage entry identifier. |
59
|
|
|
* |
60
|
|
|
* @return boolean |
61
|
|
|
* |
62
|
|
|
* @since 1.0 |
63
|
|
|
*/ |
64
|
|
|
public function deleteItem($key) |
65
|
|
|
{ |
66
|
|
|
if ($this->hasItem($key)) |
67
|
|
|
{ |
68
|
|
|
return xcache_unset($key); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// If the item doesn't exist, no error |
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Persists a cache item immediately. |
77
|
|
|
* |
78
|
|
|
* @param CacheItemInterface $item The cache item to save. |
79
|
|
|
* |
80
|
|
|
* @return static The invoked object. |
81
|
|
|
*/ |
82
|
|
|
public function save(CacheItemInterface $item) |
83
|
|
|
{ |
84
|
|
|
// If we are able to find out when the item expires - find out. Else bail. |
85
|
|
|
if ($item instanceof HasExpirationDateInterface) |
86
|
|
|
{ |
87
|
|
|
$ttl = $this->convertItemExpiryToSeconds($item); |
88
|
|
|
} |
89
|
|
|
else |
90
|
|
|
{ |
91
|
|
|
$ttl = 0; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return xcache_set($item->getKey(), $item->get(), $ttl); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Method to determine whether a storage entry has been set for a key. |
99
|
|
|
* |
100
|
|
|
* @param string $key The storage entry identifier. |
101
|
|
|
* |
102
|
|
|
* @return boolean |
103
|
|
|
* |
104
|
|
|
* @since 1.0 |
105
|
|
|
*/ |
106
|
|
|
public function hasItem($key) |
107
|
|
|
{ |
108
|
|
|
return xcache_isset($key); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Test to see if the CacheItemPoolInterface is available |
113
|
|
|
* |
114
|
|
|
* @return boolean True on success, false otherwise |
115
|
|
|
* |
116
|
|
|
* @since __DEPLOY_VERSION__ |
117
|
|
|
*/ |
118
|
|
|
public static function isSupported() |
119
|
|
|
{ |
120
|
|
|
// XCache is not supported on CLI |
121
|
|
|
return extension_loaded('xcache') && php_sapi_name() != 'cli'; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|