MediaWiki  1.23.2
ProcessCacheLRU.php
Go to the documentation of this file.
1 <?php
30  protected $cache = array(); // (key => prop => value)
32  protected $cacheTimes = array(); // (key => prop => UNIX timestamp)
33 
34  protected $maxCacheKeys; // integer; max entries
35 
40  public function __construct( $maxKeys ) {
41  if ( !is_int( $maxKeys ) || $maxKeys < 1 ) {
42  throw new UnexpectedValueException( __METHOD__ . " must be given an integer >= 1" );
43  }
44  $this->maxCacheKeys = $maxKeys;
45  }
46 
57  public function set( $key, $prop, $value ) {
58  if ( isset( $this->cache[$key] ) ) {
59  $this->ping( $key ); // push to top
60  } elseif ( count( $this->cache ) >= $this->maxCacheKeys ) {
61  reset( $this->cache );
62  $evictKey = key( $this->cache );
63  unset( $this->cache[$evictKey] );
64  unset( $this->cacheTimes[$evictKey] );
65  }
66  $this->cache[$key][$prop] = $value;
67  $this->cacheTimes[$key][$prop] = time();
68  }
69 
78  public function has( $key, $prop, $maxAge = 0 ) {
79  if ( isset( $this->cache[$key][$prop] ) ) {
80  return ( $maxAge <= 0 || ( time() - $this->cacheTimes[$key][$prop] ) <= $maxAge );
81  }
82 
83  return false;
84  }
85 
95  public function get( $key, $prop ) {
96  if ( isset( $this->cache[$key][$prop] ) ) {
97  $this->ping( $key ); // push to top
98  return $this->cache[$key][$prop];
99  } else {
100  return null;
101  }
102  }
103 
110  public function clear( $keys = null ) {
111  if ( $keys === null ) {
112  $this->cache = array();
113  $this->cacheTimes = array();
114  } else {
115  foreach ( (array)$keys as $key ) {
116  unset( $this->cache[$key] );
117  unset( $this->cacheTimes[$key] );
118  }
119  }
120  }
121 
127  protected function ping( $key ) {
128  $item = $this->cache[$key];
129  unset( $this->cache[$key] );
130  $this->cache[$key] = $item;
131  }
132 }
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ProcessCacheLRU\has
has( $key, $prop, $maxAge=0)
Check if a property field exists for a cache entry.
Definition: ProcessCacheLRU.php:76
cache
you have access to all of the normal MediaWiki so you can get a DB use the cache
Definition: maintenance.txt:52
key
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
ProcessCacheLRU\__construct
__construct( $maxKeys)
Definition: ProcessCacheLRU.php:38
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ProcessCacheLRU\$cacheTimes
Array $cacheTimes
Definition: ProcessCacheLRU.php:30
$value
$value
Definition: styleTest.css.php:45
ProcessCacheLRU\clear
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
Definition: ProcessCacheLRU.php:108
ProcessCacheLRU\ping
ping( $key)
Push an entry to the top of the cache.
Definition: ProcessCacheLRU.php:125
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$keys
$keys
Definition: testCompression.php:63
ProcessCacheLRU\$cache
Array $cache
Definition: ProcessCacheLRU.php:29
ProcessCacheLRU
Handles per process caching of items.
Definition: ProcessCacheLRU.php:28
ProcessCacheLRU\$maxCacheKeys
$maxCacheKeys
Definition: ProcessCacheLRU.php:32