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
|
|
|
* @deprecated The joomla/cache package is deprecated |
21
|
|
|
*/ |
22
|
|
|
class Wincache extends AbstractCacheItemPool |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* This will wipe out the entire cache's keys |
26
|
|
|
* |
27
|
|
|
* @return boolean True if the pool was successfully cleared. False if there was an error. |
28
|
|
|
* |
29
|
|
|
* @since 1.0 |
30
|
|
|
*/ |
31
|
|
|
public function clear() |
32
|
|
|
{ |
33
|
|
|
return wincache_ucache_clear(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns a Cache Item representing the specified key. |
38
|
|
|
* |
39
|
|
|
* @param string $key The key for which to return the corresponding Cache Item. |
40
|
|
|
* |
41
|
|
|
* @return CacheItemInterface The corresponding Cache Item. |
42
|
|
|
* |
43
|
|
|
* @since __DEPLOY_VERSION__ |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function getItem($key) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$item = new Item($key); |
|
|
|
|
48
|
|
|
$success = true; |
49
|
|
|
$value = wincache_ucache_get($key, $success); |
50
|
|
|
|
51
|
|
|
if ($success) |
52
|
|
|
{ |
53
|
|
|
$item->set($value); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $item; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Removes the item from the pool. |
61
|
|
|
* |
62
|
|
|
* @param string $key The key to delete. |
63
|
|
|
* |
64
|
|
|
* @return boolean True if the item was successfully removed. False if there was an error. |
65
|
|
|
* |
66
|
|
|
* @since __DEPLOY_VERSION__ |
67
|
|
|
*/ |
68
|
|
|
public function deleteItem($key) |
69
|
|
|
{ |
70
|
|
|
if ($this->hasItem($key)) |
71
|
|
|
{ |
72
|
|
|
return wincache_ucache_delete($key); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// If the item doesn't exist, no error |
76
|
|
|
return true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Persists a cache item immediately. |
81
|
|
|
* |
82
|
|
|
* @param CacheItemInterface $item The cache item to save. |
83
|
|
|
* |
84
|
|
|
* @return boolean True if the item was successfully persisted. False if there was an error. |
85
|
|
|
* |
86
|
|
|
* @since __DEPLOY_VERSION__ |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function save(CacheItemInterface $item) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
// If we are able to find out when the item expires - find out. Else bail. |
91
|
|
|
if ($item instanceof HasExpirationDateInterface) |
92
|
|
|
{ |
93
|
|
|
$ttl = $this->convertItemExpiryToSeconds($item); |
94
|
|
|
} |
95
|
|
|
else |
96
|
|
|
{ |
97
|
|
|
$ttl = 0; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return wincache_ucache_set($item->getKey(), $item->get(), $ttl); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Confirms if the cache contains specified cache item. |
105
|
|
|
* |
106
|
|
|
* @param string $key The key for which to check existence. |
107
|
|
|
* |
108
|
|
|
* @return boolean True if item exists in the cache, false otherwise. |
109
|
|
|
* |
110
|
|
|
* @since 1.0 |
111
|
|
|
*/ |
112
|
|
|
public function hasItem($key) |
113
|
|
|
{ |
114
|
|
|
return wincache_ucache_exists($key); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Test to see if the CacheItemPoolInterface is available |
119
|
|
|
* |
120
|
|
|
* @return boolean True on success, false otherwise |
121
|
|
|
* |
122
|
|
|
* @since __DEPLOY_VERSION__ |
123
|
|
|
*/ |
124
|
|
|
public static function isSupported(): bool |
125
|
|
|
{ |
126
|
|
|
return extension_loaded('wincache') && function_exists('wincache_ucache_get') && !strcmp(ini_get('wincache.ucenabled'), "1"); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.