fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / zendframework / zend-cache / doc / book / storage / capabilities.md
blob95009450428bb73b984b8bae8638a25f306d8c7c
1 # Storage Capabilities
3 Storage capabilities describe how a storage adapter works, and which features it
4 supports.
6 To get capabilities of a storage adapter, you can use the method
7 `getCapabilities()`, but only the storage adapter and its plugins have
8 permissions to change them.
10 Because capabilities are mutable, you can subscribe to the "change" event to get
11 notifications; see the examples for details.
13 If you are writing your own plugin or adapter, you can also change capabilities
14 because you have access to the marker object and can create your own marker to
15 instantiate a new instance of `Zend\Cache\Storage\Capabilities`.
17 ## Available Methods
19 ```php
20 namespace Zend\Cache\Storage;
22 use ArrayObject;
23 use stdClass;
24 use Zend\Cache\Exception;
25 use Zend\EventManager\EventsCapableInterface;
27 class Capabilities
29     /**
30      * Constructor
31      *
32      * @param StorageInterface  $storage
33      * @param stdClass          $marker
34      * @param array             $capabilities
35      * @param null|Capabilities $baseCapabilities
36      */
37     public function __construct(
38         StorageInterface $storage,
39         stdClass $marker,
40         array $capabilities = [],
41         Capabilities $baseCapabilities = null
42     );
44     /**
45      * Get the storage adapter
46      *
47      * @return StorageInterface
48      */
49     public function getAdapter();
51     /**
52      * Get supported datatypes
53      *
54      * @return array
55      */
56     public function getSupportedDatatypes();
58     /**
59      * Set supported datatypes
60      *
61      * @param  stdClass $marker
62      * @param  array $datatypes
63      * @throws Exception\InvalidArgumentException
64      * @return Capabilities Fluent interface
65      */
66     public function setSupportedDatatypes(stdClass $marker, array $datatypes);
68     /**
69      * Get supported metadata
70      *
71      * @return array
72      */
73     public function getSupportedMetadata();
75     /**
76      * Set supported metadata
77      *
78      * @param  stdClass $marker
79      * @param  string[] $metadata
80      * @throws Exception\InvalidArgumentException
81      * @return Capabilities Fluent interface
82      */
83     public function setSupportedMetadata(stdClass $marker, array $metadata);
85     /**
86      * Get minimum supported time-to-live
87      *
88      * @return int 0 means items never expire
89      */
90     public function getMinTtl();
92     /**
93      * Set minimum supported time-to-live
94      *
95      * @param  stdClass $marker
96      * @param  int $minTtl
97      * @throws Exception\InvalidArgumentException
98      * @return Capabilities Fluent interface
99      */
100     public function setMinTtl(stdClass $marker, $minTtl);
102     /**
103      * Get maximum supported time-to-live
104      *
105      * @return int 0 means infinite
106      */
107     public function getMaxTtl();
109     /**
110      * Set maximum supported time-to-live
111      *
112      * @param  stdClass $marker
113      * @param  int $maxTtl
114      * @throws Exception\InvalidArgumentException
115      * @return Capabilities Fluent interface
116      */
117     public function setMaxTtl(stdClass $marker, $maxTtl);
119     /**
120      * Is the time-to-live handled static (on write)
121      * or dynamic (on read)
122      *
123      * @return bool
124      */
125     public function getStaticTtl();
127     /**
128      * Set if the time-to-live handled static (on write) or dynamic (on read)
129      *
130      * @param  stdClass $marker
131      * @param  bool $flag
132      * @return Capabilities Fluent interface
133      */
134     public function setStaticTtl(stdClass $marker, $flag);
136     /**
137      * Get time-to-live precision
138      *
139      * @return float
140      */
141     public function getTtlPrecision();
143     /**
144      * Set time-to-live precision
145      *
146      * @param  stdClass $marker
147      * @param  float $ttlPrecision
148      * @throws Exception\InvalidArgumentException
149      * @return Capabilities Fluent interface
150      */
151     public function setTtlPrecision(stdClass $marker, $ttlPrecision);
153     /**
154      * Get use request time
155      *
156      * @return bool
157      */
158     public function getUseRequestTime();
160     /**
161      * Set use request time
162      *
163      * @param  stdClass $marker
164      * @param  bool $flag
165      * @return Capabilities Fluent interface
166      */
167     public function setUseRequestTime(stdClass $marker, $flag);
169     /**
170      * Get if expired items are readable
171      *
172      * @return bool
173      * @deprecated This capability has been deprecated and will be removed in the future.
174      *             Please use getStaticTtl() instead
175      */
176     public function getExpiredRead();
178     /**
179      * Set if expired items are readable
180      *
181      * @param  stdClass $marker
182      * @param  bool $flag
183      * @return Capabilities Fluent interface
184      * @deprecated This capability has been deprecated and will be removed in the future.
185      *             Please use setStaticTtl() instead
186      */
187     public function setExpiredRead(stdClass $marker, $flag);
189     /**
190      * Get maximum key lenth
191      *
192      * @return int -1 means unknown, 0 means infinite
193      */
194     public function getMaxKeyLength();
196     /**
197      * Set maximum key length
198      *
199      * @param  stdClass $marker
200      * @param  int $maxKeyLength
201      * @throws Exception\InvalidArgumentException
202      * @return Capabilities Fluent interface
203      */
204     public function setMaxKeyLength(stdClass $marker, $maxKeyLength);
206     /**
207      * Get if namespace support is implemented as prefix
208      *
209      * @return bool
210      */
211     public function getNamespaceIsPrefix();
213     /**
214      * Set if namespace support is implemented as prefix
215      *
216      * @param  stdClass $marker
217      * @param  bool $flag
218      * @return Capabilities Fluent interface
219      */
220     public function setNamespaceIsPrefix(stdClass $marker, $flag);
222     /**
223      * Get namespace separator if namespace is implemented as prefix
224      *
225      * @return string
226      */
227     public function getNamespaceSeparator();
229     /**
230      * Set the namespace separator if namespace is implemented as prefix
231      *
232      * @param  stdClass $marker
233      * @param  string $separator
234      * @return Capabilities Fluent interface
235      */
236     public function setNamespaceSeparator(stdClass $marker, $separator);
240 ## Examples
242 ### Get storage capabilities and do specific stuff based on them
244 ```php
245 use Zend\Cache\StorageFactory;
247 $cache = StorageFactory::adapterFactory('filesystem');
248 $supportedDatatypes = $cache->getCapabilities()->getSupportedDatatypes();
250 // now you can run specific stuff in base of supported feature
251 if ($supportedDatatypes['object']) {
252     $cache->set($key, $object);
253 } else {
254     $cache->set($key, serialize($object));
258 ### Listen to the change event
260 ```php
261 use Zend\Cache\StorageFactory;
263 $cache = StorageFactory::adapterFactory('filesystem', [
264     'no_atime' => false,
267 // Catching capability changes
268 $cache->getEventManager()->attach('capability', function($event) {
269     echo count($event->getParams()) . ' capabilities changed';
272 // change option which changes capabilities
273 $cache->getOptions()->setNoATime(true);