filebackend: clean up some comments and remove unused FileBackendStoreOpHandle field
[lhc/web/wiklou.git] / includes / libs / ProcessCacheLRU.php
1 <?php
2 /**
3 * Per-process memory cache for storing items.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Cache
22 */
23
24 /**
25 * Class for process caching individual properties of expiring items
26 *
27 * When the key for an entire item is deleted, all properties for it are deleted
28 *
29 * @ingroup Cache
30 * @deprecated Since 1.32 Use MapCacheLRU instead
31 */
32 class ProcessCacheLRU {
33 /** @var MapCacheLRU */
34 protected $cache;
35
36 /**
37 * @param int $maxKeys Maximum number of entries allowed (min 1).
38 * @throws UnexpectedValueException When $maxCacheKeys is not an int or =< 0.
39 */
40 public function __construct( $maxKeys ) {
41 $this->cache = new MapCacheLRU( $maxKeys );
42 }
43
44 /**
45 * Set a property field for a cache entry.
46 * This will prune the cache if it gets too large based on LRU.
47 * If the item is already set, it will be pushed to the top of the cache.
48 *
49 * @param string $key
50 * @param string $prop
51 * @param mixed $value
52 * @return void
53 */
54 public function set( $key, $prop, $value ) {
55 $this->cache->setField( $key, $prop, $value );
56 }
57
58 /**
59 * Check if a property field exists for a cache entry.
60 *
61 * @param string $key
62 * @param string $prop
63 * @param float $maxAge Ignore items older than this many seconds (since 1.21)
64 * @return bool
65 */
66 public function has( $key, $prop, $maxAge = 0.0 ) {
67 return $this->cache->hasField( $key, $prop, $maxAge );
68 }
69
70 /**
71 * Get a property field for a cache entry.
72 * This returns null if the property is not set.
73 * If the item is already set, it will be pushed to the top of the cache.
74 *
75 * @param string $key
76 * @param string $prop
77 * @return mixed
78 */
79 public function get( $key, $prop ) {
80 return $this->cache->getField( $key, $prop );
81 }
82
83 /**
84 * Clear one or several cache entries, or all cache entries.
85 *
86 * @param string|array|null $keys
87 * @return void
88 */
89 public function clear( $keys = null ) {
90 $this->cache->clear( $keys );
91 }
92
93 /**
94 * Resize the maximum number of cache entries, removing older entries as needed
95 *
96 * @param int $maxKeys
97 * @return void
98 * @throws UnexpectedValueException
99 */
100 public function resize( $maxKeys ) {
101 $this->cache->setMaxSize( $maxKeys );
102 }
103
104 /**
105 * Get cache size
106 * @return int
107 */
108 public function getSize() {
109 return $this->cache->getMaxSize();
110 }
111 }