3 * Per-process memory cache for storing items.
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.
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.
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
25 * Class for process caching individual properties of expiring items
27 * When the key for an entire item is deleted, all properties for it are deleted
30 * @deprecated Since 1.32 Use MapCacheLRU instead
32 class ProcessCacheLRU
{
33 /** @var MapCacheLRU */
37 * @param int $maxKeys Maximum number of entries allowed (min 1).
38 * @throws UnexpectedValueException When $maxCacheKeys is not an int or =< 0.
40 public function __construct( $maxKeys ) {
41 $this->cache
= new MapCacheLRU( $maxKeys );
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.
54 public function set( $key, $prop, $value ) {
55 $this->cache
->setField( $key, $prop, $value );
59 * Check if a property field exists for a cache entry.
63 * @param float $maxAge Ignore items older than this many seconds (since 1.21)
66 public function has( $key, $prop, $maxAge = 0.0 ) {
67 return $this->cache
->hasField( $key, $prop, $maxAge );
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.
79 public function get( $key, $prop ) {
80 return $this->cache
->getField( $key, $prop );
84 * Clear one or several cache entries, or all cache entries.
86 * @param string|array|null $keys
89 public function clear( $keys = null ) {
90 $this->cache
->clear( $keys );
94 * Resize the maximum number of cache entries, removing older entries as needed
98 * @throws UnexpectedValueException
100 public function resize( $maxKeys ) {
101 $this->cache
->setMaxSize( $maxKeys );
108 public function getSize() {
109 return $this->cache
->getMaxSize();