MediaWiki REL1_31
ProcessCacheLRU.php
Go to the documentation of this file.
1<?php
23use Wikimedia\Assert\Assert;
24
34 protected $cache = []; // (key => prop => value)
35
37 protected $cacheTimes = []; // (key => prop => UNIX timestamp)
38
39 protected $maxCacheKeys; // integer; max entries
40
45 public function __construct( $maxKeys ) {
46 $this->resize( $maxKeys );
47 }
48
59 public function set( $key, $prop, $value ) {
60 if ( isset( $this->cache[$key] ) ) {
61 $this->ping( $key );
62 } elseif ( count( $this->cache ) >= $this->maxCacheKeys ) {
63 reset( $this->cache );
64 $evictKey = key( $this->cache );
65 unset( $this->cache[$evictKey] );
66 unset( $this->cacheTimes[$evictKey] );
67 }
68 $this->cache[$key][$prop] = $value;
69 $this->cacheTimes[$key][$prop] = microtime( true );
70 }
71
80 public function has( $key, $prop, $maxAge = 0.0 ) {
81 if ( isset( $this->cache[$key][$prop] ) ) {
82 return ( $maxAge <= 0 ||
83 ( microtime( true ) - $this->cacheTimes[$key][$prop] ) <= $maxAge
84 );
85 }
86
87 return false;
88 }
89
99 public function get( $key, $prop ) {
100 if ( !isset( $this->cache[$key][$prop] ) ) {
101 return null;
102 }
103 $this->ping( $key );
104 return $this->cache[$key][$prop];
105 }
106
113 public function clear( $keys = null ) {
114 if ( $keys === null ) {
115 $this->cache = [];
116 $this->cacheTimes = [];
117 } else {
118 foreach ( (array)$keys as $key ) {
119 unset( $this->cache[$key] );
120 unset( $this->cacheTimes[$key] );
121 }
122 }
123 }
124
132 public function resize( $maxKeys ) {
133 Assert::parameterType( 'integer', $maxKeys, '$maxKeys' );
134 Assert::parameter( $maxKeys > 0, '$maxKeys', 'must be above zero' );
135
136 $this->maxCacheKeys = $maxKeys;
137 while ( count( $this->cache ) > $this->maxCacheKeys ) {
138 reset( $this->cache );
139 $evictKey = key( $this->cache );
140 unset( $this->cache[$evictKey] );
141 unset( $this->cacheTimes[$evictKey] );
142 }
143 }
144
150 protected function ping( $key ) {
151 $item = $this->cache[$key];
152 unset( $this->cache[$key] );
153 $this->cache[$key] = $item;
154 }
155
160 public function getSize() {
161 return $this->maxCacheKeys;
162 }
163}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Class for process caching individual properties of expiring items.
clear( $keys=null)
Clear one or several cache entries, or all cache entries.
has( $key, $prop, $maxAge=0.0)
Check if a property field exists for a cache entry.
__construct( $maxKeys)
ping( $key)
Push an entry to the top of the cache.
resize( $maxKeys)
Resize the maximum number of cache entries, removing older entries as needed.
getSize()
Get cache size.
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:26
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
the array() calling protocol came about after MediaWiki 1.4rc1.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
you have access to all of the normal MediaWiki so you can get a DB use the cache