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 Psr\Cache\CacheItemInterface; |
12
|
|
|
use Joomla\Cache\Item\Item; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Runtime memory cache driver. |
16
|
|
|
* |
17
|
|
|
* @since 1.0 |
18
|
|
|
*/ |
19
|
|
|
class Runtime extends Cache |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The runtime cache storage array. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
* @since 1.0 |
26
|
|
|
*/ |
27
|
|
|
private static $store = array(); |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* This will wipe out the entire cache's keys |
31
|
|
|
* |
32
|
|
|
* @return boolean The result of the clear operation. |
33
|
|
|
* |
34
|
|
|
* @since 1.0 |
35
|
|
|
*/ |
36
|
1 |
|
public function clear() |
37
|
|
|
{ |
38
|
1 |
|
self::$store = array(); |
39
|
|
|
|
40
|
1 |
|
return true; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Method to get a storage entry value from a key. |
45
|
|
|
* |
46
|
|
|
* @param string $key The storage entry identifier. |
47
|
|
|
* |
48
|
|
|
* @return CacheItemInterface |
49
|
|
|
* |
50
|
|
|
* @since 1.0 |
51
|
|
|
*/ |
52
|
1 |
|
public function getItem($key) |
53
|
|
|
{ |
54
|
1 |
|
$item = new Item($key); |
55
|
|
|
|
56
|
1 |
|
if (isset(self::$store[$key])) |
57
|
1 |
|
{ |
58
|
1 |
|
$item->set(self::$store[$key]); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
1 |
|
return $item; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Method to remove a storage entry for a key. |
66
|
|
|
* |
67
|
|
|
* @param string $key The storage entry identifier. |
68
|
|
|
* |
69
|
|
|
* @return boolean |
70
|
|
|
* |
71
|
|
|
* @since 1.0 |
72
|
|
|
*/ |
73
|
1 |
|
public function deleteItem($key) |
74
|
|
|
{ |
75
|
1 |
|
unset(self::$store[$key]); |
76
|
|
|
|
77
|
1 |
|
return true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Persists a cache item immediately. |
82
|
|
|
* |
83
|
|
|
* @param CacheItemInterface $item The cache item to save. |
84
|
|
|
* |
85
|
|
|
* @return static The invoked object. |
86
|
|
|
*/ |
87
|
1 |
|
public function save(CacheItemInterface $item) |
88
|
|
|
{ |
89
|
1 |
|
self::$store[$item->getKey()] = $item->get(); |
90
|
|
|
|
91
|
1 |
|
return true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Method to determine whether a storage entry has been set for a key. |
96
|
|
|
* |
97
|
|
|
* @param string $key The storage entry identifier. |
98
|
|
|
* |
99
|
|
|
* @return boolean |
100
|
|
|
* |
101
|
|
|
* @since 1.0 |
102
|
|
|
*/ |
103
|
1 |
|
public function hasItem($key) |
104
|
|
|
{ |
105
|
1 |
|
return isset(self::$store[$key]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Test to see if the CacheItemPoolInterface is available |
110
|
|
|
* |
111
|
|
|
* @return boolean True on success, false otherwise |
112
|
|
|
* |
113
|
|
|
* @since __DEPLOY_VERSION__ |
114
|
|
|
*/ |
115
|
|
|
public static function isSupported() |
116
|
|
|
{ |
117
|
|
|
return true; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|