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
|
|
|
* WinCache cache driver for the Joomla Framework. |
18
|
|
|
* |
19
|
|
|
* @since 1.0 |
20
|
|
|
*/ |
21
|
|
|
class Wincache 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
|
|
|
$success = true; |
47
|
|
|
$value = wincache_ucache_get($key, $success); |
48
|
|
|
|
49
|
|
|
if ($success) |
50
|
|
|
{ |
51
|
|
|
$item->set($value); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $item; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Method to remove a storage entry for a key. |
59
|
|
|
* |
60
|
|
|
* @param string $key The storage entry identifier. |
61
|
|
|
* |
62
|
|
|
* @return boolean |
63
|
|
|
* |
64
|
|
|
* @since 1.0 |
65
|
|
|
*/ |
66
|
|
|
public function deleteItem($key) |
67
|
|
|
{ |
68
|
|
|
if ($this->hasItem($key)) |
69
|
|
|
{ |
70
|
|
|
return wincache_ucache_delete($key); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// If the item doesn't exist, no error |
74
|
|
|
return true; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Persists a cache item immediately. |
79
|
|
|
* |
80
|
|
|
* @param CacheItemInterface $item The cache item to save. |
81
|
|
|
* |
82
|
|
|
* @return static The invoked object. |
83
|
|
|
*/ |
84
|
|
|
public function save(CacheItemInterface $item) |
85
|
|
|
{ |
86
|
|
|
// If we are able to find out when the item expires - find out. Else bail. |
87
|
|
|
if ($item instanceof HasExpirationDateInterface) |
88
|
|
|
{ |
89
|
|
|
$ttl = $this->convertItemExpiryToSeconds($item); |
90
|
|
|
} |
91
|
|
|
else |
92
|
|
|
{ |
93
|
|
|
$ttl = 0; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return wincache_ucache_set($item->getKey(), $item->get(), $ttl); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Method to determine whether a storage entry has been set for a key. |
101
|
|
|
* |
102
|
|
|
* @param string $key The storage entry identifier. |
103
|
|
|
* |
104
|
|
|
* @return boolean |
105
|
|
|
* |
106
|
|
|
* @since 1.0 |
107
|
|
|
*/ |
108
|
|
|
public function hasItem($key) |
109
|
|
|
{ |
110
|
|
|
return wincache_ucache_exists($key); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Test to see if the CacheItemPoolInterface is available |
115
|
|
|
* |
116
|
|
|
* @return boolean True on success, false otherwise |
117
|
|
|
* |
118
|
|
|
* @since __DEPLOY_VERSION__ |
119
|
|
|
*/ |
120
|
|
|
public static function isSupported() |
121
|
|
|
{ |
122
|
|
|
return (extension_loaded('wincache') && function_exists('wincache_ucache_get') && !strcmp(ini_get('wincache.ucenabled'), "1")); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|