1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* AppserverIo\Storage\StackableStorage |
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
|
|
|
* A storage implementation that uses a \Stackable to hold the data persistent |
25
|
|
|
* in memory. |
26
|
|
|
* |
27
|
|
|
* This storage will completely be flushed when the the object is destroyed, |
28
|
|
|
* there is no automatic persistence functionality available. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link http://github.com/appserver-io/storage |
34
|
|
|
* @link http://www.appserver.io |
35
|
|
|
* @deprecated Use \AppserverIo\Storage\ThreadedStorage instead |
36
|
|
|
*/ |
37
|
|
|
class StackableStorage extends GenericStackable implements StorageInterface |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register the trait that provides basic storage functionality. |
42
|
|
|
* |
43
|
|
|
* @var \Trait |
44
|
|
|
*/ |
45
|
|
|
use StorageTrait; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Passes the configuration and initializes the storage. |
49
|
|
|
* |
50
|
|
|
* The identifier will be set after the init() function has been invoked, so it'll overwrite the one |
51
|
|
|
* specified in the configuration if set. |
52
|
|
|
* |
53
|
|
|
* @return void |
|
|
|
|
54
|
|
|
*/ |
55
|
|
|
public function __construct() |
56
|
|
|
{ |
57
|
|
|
$this->flush(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* (non-PHPdoc) |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
* @see \AppserverIo\Storage\StorageInterface::collectGarbage() |
65
|
|
|
*/ |
66
|
|
|
public function collectGarbage() |
67
|
|
|
{ |
68
|
|
|
// nothing to do here, because gc is handled by memcache |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* (non-PHPdoc) |
73
|
|
|
* |
74
|
|
|
* @param string $tag The tag to search for |
75
|
|
|
* |
76
|
|
|
* @return array An array with the identifier (key) and content (value) of all matching entries. An empty array if no entries matched |
77
|
|
|
* @see \AppserverIo\Storage\StorageInterface::getByTag() |
78
|
|
|
*/ |
79
|
|
|
public function getByTag($tag) |
80
|
|
|
{ |
81
|
|
|
return $this->get($tag); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* (non-PHPdoc) |
86
|
|
|
* |
87
|
|
|
* @return mixed The storage object itself |
88
|
|
|
* @see \AppserverIo\Storage\StorageInterface::getStorage() |
89
|
|
|
*/ |
90
|
|
|
public function getStorage() |
91
|
|
|
{ |
92
|
|
|
return; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* (non-PHPdoc) |
97
|
|
|
* |
98
|
|
|
* @param string $entryIdentifier Something which identifies the data - depends on concrete cache |
99
|
|
|
* @param mixed $data The data to cache - also depends on the concrete cache implementation |
100
|
|
|
* @param array $tags Tags to associate with this cache entry |
101
|
|
|
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, |
102
|
|
|
* the default lifetime is used. "0" means unlimited lifetime. |
103
|
|
|
* |
104
|
|
|
* @return void |
105
|
|
|
* |
106
|
|
|
* @see \AppserverIo\Storage\StorageInterface::set() |
107
|
|
|
*/ |
108
|
|
|
public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null) |
109
|
|
|
{ |
110
|
|
|
|
111
|
|
|
// set the data in the storage |
112
|
|
|
$this[$entryIdentifier] = $data; |
113
|
|
|
|
114
|
|
|
// if tags has been set, tag the data additionally |
115
|
|
|
foreach ($tags as $tag) { |
116
|
|
|
// assemble the tag data |
117
|
|
|
$tagData = $this->get($tag); |
118
|
|
|
if (is_array($tagData) && in_array($entryIdentifier, $tagData, true) === true) { |
119
|
|
|
// do nothing here |
120
|
|
|
} elseif (is_array($tagData) && in_array($entryIdentifier, $tagData, true) === false) { |
121
|
|
|
$tagData[] = $entryIdentifier; |
122
|
|
|
} else { |
123
|
|
|
$tagData = array($entryIdentifier); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// tag the data |
127
|
|
|
$this[$tag] = $tagData; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* (non-PHPdoc) |
133
|
|
|
* |
134
|
|
|
* @param string $entryIdentifier Something which identifies the cache entry - depends on concrete cache |
135
|
|
|
* |
136
|
|
|
* @return mixed |
137
|
|
|
* @see \AppserverIo\Storage\StorageInterface::get() |
138
|
|
|
*/ |
139
|
|
|
public function get($entryIdentifier) |
140
|
|
|
{ |
141
|
|
|
return $this[$entryIdentifier]; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* (non-PHPdoc) |
146
|
|
|
* |
147
|
|
|
* @param string $entryIdentifier An identifier specifying the cache entry |
148
|
|
|
* |
149
|
|
|
* @return boolean TRUE if such an entry exists, FALSE if not |
150
|
|
|
* @see \AppserverIo\Storage\StorageInterface::has() |
151
|
|
|
*/ |
152
|
|
|
public function has($entryIdentifier) |
153
|
|
|
{ |
154
|
|
|
return isset($this[$entryIdentifier]); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* (non-PHPdoc) |
159
|
|
|
* |
160
|
|
|
* @param string $entryIdentifier An identifier specifying the cache entry |
161
|
|
|
* |
162
|
|
|
* @return boolean TRUE if such an entry exists, FALSE if not |
163
|
|
|
* @see \AppserverIo\Storage\StorageInterface::remove() |
164
|
|
|
*/ |
165
|
|
|
public function remove($entryIdentifier) |
166
|
|
|
{ |
167
|
|
|
if ($this->has($entryIdentifier)) { |
168
|
|
|
unset($this[$entryIdentifier]); |
169
|
|
|
return true; |
170
|
|
|
} |
171
|
|
|
return false; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* (non-PHPdoc) |
176
|
|
|
* |
177
|
|
|
* @return array |
178
|
|
|
* @see \AppserverIo\Storage\StorageInterface::getAllKeys() |
179
|
|
|
*/ |
180
|
|
|
public function getAllKeys() |
181
|
|
|
{ |
182
|
|
|
$keys = array(); |
183
|
|
|
foreach ((array) $this as $key => $value) { |
184
|
|
|
$keys[] = $key; |
185
|
|
|
} |
186
|
|
|
return $keys; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
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.