1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Storage\ApcuStorage |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link http://github.com/appserver-io/storage |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Storage; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class ApcuStorage |
25
|
|
|
* |
26
|
|
|
* @author Tim Wagner <[email protected]> |
27
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link http://github.com/appserver-io/storage |
30
|
|
|
* @link http://www.appserver.io |
31
|
|
|
*/ |
32
|
|
|
class ApcuStorage extends AbstractStorage |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Initializes the storage when the instance is constructed and the __wakeup() method is invoked. |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
* @see AppserverIo\Storage\AbstractStorage::init(); |
40
|
|
|
*/ |
41
|
|
|
public function init() |
42
|
|
|
{ |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* (non-PHPdoc) |
48
|
|
|
* |
49
|
|
|
* @param string $entryIdentifier Something which identifies the data - depends on concrete cache |
50
|
|
|
* @param mixed $data The data to cache - also depends on the concrete cache implementation |
51
|
|
|
* @param array $tags Tags to associate with this cache entry |
52
|
|
|
* @param integer $lifetime Lifetime of this cache entry in seconds. |
53
|
|
|
* If NULL is specified, the default lifetime is used. "0" means unlimited lifetime. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
* |
57
|
|
|
* @see \AppserverIo\Storage\StorageInterface::set() |
58
|
|
|
*/ |
59
|
|
|
public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null) |
60
|
|
|
{ |
61
|
|
|
// add the passed value to the storage |
62
|
|
|
apc_store($entryIdentifier, $data, $lifetime); |
63
|
|
|
|
64
|
|
|
// if tags has been set, tag the data additionally |
65
|
|
|
foreach ($tags as $tag) { |
66
|
|
|
$tagData = $this->get($tag); |
67
|
|
|
if (is_array($tagData) && in_array($entryIdentifier, $tagData, true) === true) { |
68
|
|
|
// do nothing here |
69
|
|
|
} elseif (is_array($tagData) && in_array($entryIdentifier, $tagData, true) === false) { |
70
|
|
|
$tagData[] = $entryIdentifier; |
71
|
|
|
} else { |
72
|
|
|
$tagData = array($entryIdentifier); |
73
|
|
|
} |
74
|
|
|
apc_store($tag, $tagData); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* (non-PHPdoc) |
80
|
|
|
* |
81
|
|
|
* @param string $entryIdentifier Something which identifies the cache entry - depends on concrete cache |
82
|
|
|
* |
83
|
|
|
* @return mixed |
84
|
|
|
* @see \AppserverIo\Storage\StorageInterface::get() |
85
|
|
|
*/ |
86
|
|
|
public function get($entryIdentifier) |
87
|
|
|
{ |
88
|
|
|
return apc_fetch($entryIdentifier); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* (non-PHPdoc) |
93
|
|
|
* |
94
|
|
|
* @param string $entryIdentifier An identifier specifying the cache entry |
95
|
|
|
* |
96
|
|
|
* @return boolean TRUE if such an entry exists, FALSE if not |
97
|
|
|
* @see \AppserverIo\Storage\StorageInterface::has() |
98
|
|
|
*/ |
99
|
|
|
public function has($entryIdentifier) |
100
|
|
|
{ |
101
|
|
|
return apc_exists($entryIdentifier); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* (non-PHPdoc) |
106
|
|
|
* |
107
|
|
|
* @param string $entryIdentifier An identifier specifying the cache entry |
108
|
|
|
* |
109
|
|
|
* @return boolean TRUE if such an entry exists, FALSE if not |
110
|
|
|
* @see \AppserverIo\Storage\StorageInterface::remove() |
111
|
|
|
*/ |
112
|
|
|
public function remove($entryIdentifier) |
113
|
|
|
{ |
114
|
|
|
return apc_delete($entryIdentifier); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* (non-PHPdoc) |
119
|
|
|
* |
120
|
|
|
* @return array |
121
|
|
|
* @see \AppserverIo\Storage\StorageInterface::getAllKeys() |
122
|
|
|
*/ |
123
|
|
|
public function getAllKeys() |
124
|
|
|
{ |
125
|
|
|
$iter = new \APCIterator('user'); |
126
|
|
|
$keys = array(); |
127
|
|
|
foreach ($iter as $item) { |
128
|
|
|
echo $keys[] = $item['key']; |
129
|
|
|
} |
130
|
|
|
return $keys; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|