2012-06-30 03:08:06 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Per-process memory cache for storing items.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Cache
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2017-09-24 11:17:11 +00:00
|
|
|
* Class for process caching individual properties of expiring items
|
|
|
|
|
*
|
|
|
|
|
* When the key for an entire item is deleted, all properties for it are deleted
|
|
|
|
|
*
|
2012-06-30 03:08:06 +00:00
|
|
|
* @ingroup Cache
|
2018-06-27 14:00:10 +00:00
|
|
|
* @deprecated Since 1.32 Use MapCacheLRU instead
|
2012-06-30 03:08:06 +00:00
|
|
|
*/
|
|
|
|
|
class ProcessCacheLRU {
|
2018-06-27 14:00:10 +00:00
|
|
|
/** @var MapCacheLRU */
|
|
|
|
|
protected $cache;
|
2012-06-30 03:08:06 +00:00
|
|
|
|
|
|
|
|
/**
|
2015-01-29 20:06:25 +00:00
|
|
|
* @param int $maxKeys Maximum number of entries allowed (min 1).
|
2014-03-16 19:28:18 +00:00
|
|
|
* @throws UnexpectedValueException When $maxCacheKeys is not an int or =< 0.
|
2012-06-30 03:08:06 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( $maxKeys ) {
|
2018-06-27 14:00:10 +00:00
|
|
|
$this->cache = new MapCacheLRU( $maxKeys );
|
2012-06-30 03:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a property field for a cache entry.
|
2012-11-16 20:02:42 +00:00
|
|
|
* This will prune the cache if it gets too large based on LRU.
|
2012-06-30 03:08:06 +00:00
|
|
|
* If the item is already set, it will be pushed to the top of the cache.
|
|
|
|
|
*
|
2015-01-29 20:06:25 +00:00
|
|
|
* @param string $key
|
|
|
|
|
* @param string $prop
|
|
|
|
|
* @param mixed $value
|
2012-06-30 03:08:06 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function set( $key, $prop, $value ) {
|
2018-06-27 14:00:10 +00:00
|
|
|
$this->cache->setField( $key, $prop, $value );
|
2012-06-30 03:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if a property field exists for a cache entry.
|
|
|
|
|
*
|
2015-01-29 20:06:25 +00:00
|
|
|
* @param string $key
|
|
|
|
|
* @param string $prop
|
|
|
|
|
* @param float $maxAge Ignore items older than this many seconds (since 1.21)
|
2012-06-30 03:08:06 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2014-09-25 19:04:09 +00:00
|
|
|
public function has( $key, $prop, $maxAge = 0.0 ) {
|
2018-06-27 14:00:10 +00:00
|
|
|
return $this->cache->hasField( $key, $prop, $maxAge );
|
2012-06-30 03:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a property field for a cache entry.
|
|
|
|
|
* This returns null if the property is not set.
|
|
|
|
|
* If the item is already set, it will be pushed to the top of the cache.
|
|
|
|
|
*
|
2015-01-29 20:06:25 +00:00
|
|
|
* @param string $key
|
|
|
|
|
* @param string $prop
|
2012-06-30 03:08:06 +00:00
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function get( $key, $prop ) {
|
2018-06-27 14:00:10 +00:00
|
|
|
return $this->cache->getField( $key, $prop );
|
2012-06-30 03:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-01-29 20:06:25 +00:00
|
|
|
* Clear one or several cache entries, or all cache entries.
|
2012-06-30 03:08:06 +00:00
|
|
|
*
|
2018-06-26 21:14:43 +00:00
|
|
|
* @param string|array|null $keys
|
2012-06-30 03:08:06 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function clear( $keys = null ) {
|
2018-06-27 14:00:10 +00:00
|
|
|
$this->cache->clear( $keys );
|
2012-06-30 03:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-19 00:02:19 +00:00
|
|
|
/**
|
|
|
|
|
* Resize the maximum number of cache entries, removing older entries as needed
|
|
|
|
|
*
|
2015-01-29 20:06:25 +00:00
|
|
|
* @param int $maxKeys
|
2014-04-19 00:02:19 +00:00
|
|
|
* @return void
|
2014-09-25 19:04:09 +00:00
|
|
|
* @throws UnexpectedValueException
|
2014-04-19 00:02:19 +00:00
|
|
|
*/
|
|
|
|
|
public function resize( $maxKeys ) {
|
2018-06-27 14:00:10 +00:00
|
|
|
$this->cache->setMaxSize( $maxKeys );
|
2012-06-30 03:08:06 +00:00
|
|
|
}
|
2016-08-18 06:25:37 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get cache size
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getSize() {
|
2018-06-27 14:00:10 +00:00
|
|
|
return $this->cache->getMaxSize();
|
2016-08-18 06:25:37 +00:00
|
|
|
}
|
2012-06-30 03:08:06 +00:00
|
|
|
}
|