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