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