MediaWiki  REL1_31
CachedBagOStuff.php
Go to the documentation of this file.
1 <?php
38  protected $backend;
39 
44  function __construct( BagOStuff $backend, $params = [] ) {
45  unset( $params['reportDupes'] ); // useless here
46 
47  parent::__construct( $params );
48 
49  $this->backend = $backend;
50  $this->attrMap = $backend->attrMap;
51  }
52 
53  protected function doGet( $key, $flags = 0 ) {
54  $ret = parent::doGet( $key, $flags );
55  if ( $ret === false && !$this->hasKey( $key ) ) {
56  $ret = $this->backend->doGet( $key, $flags );
57  $this->set( $key, $ret, 0, self::WRITE_CACHE_ONLY );
58  }
59  return $ret;
60  }
61 
62  public function set( $key, $value, $exptime = 0, $flags = 0 ) {
63  parent::set( $key, $value, $exptime, $flags );
64  if ( !( $flags & self::WRITE_CACHE_ONLY ) ) {
65  $this->backend->set( $key, $value, $exptime, $flags & ~self::WRITE_CACHE_ONLY );
66  }
67  return true;
68  }
69 
70  public function delete( $key, $flags = 0 ) {
71  unset( $this->bag[$key] );
72  if ( !( $flags & self::WRITE_CACHE_ONLY ) ) {
73  $this->backend->delete( $key );
74  }
75 
76  return true;
77  }
78 
79  public function setDebug( $bool ) {
80  parent::setDebug( $bool );
81  $this->backend->setDebug( $bool );
82  }
83 
84  public function deleteObjectsExpiringBefore( $date, $progressCallback = false ) {
85  parent::deleteObjectsExpiringBefore( $date, $progressCallback );
86  return $this->backend->deleteObjectsExpiringBefore( $date, $progressCallback );
87  }
88 
89  public function makeKey( $class, $component = null ) {
90  return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() );
91  }
92 
93  public function makeGlobalKey( $class, $component = null ) {
94  return call_user_func_array( [ $this->backend, __FUNCTION__ ], func_get_args() );
95  }
96 
97  // These just call the backend (tested elsewhere)
98  // @codeCoverageIgnoreStart
99 
100  public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
101  return $this->backend->lock( $key, $timeout, $expiry, $rclass );
102  }
103 
104  public function unlock( $key ) {
105  return $this->backend->unlock( $key );
106  }
107 
108  public function getLastError() {
109  return $this->backend->getLastError();
110  }
111 
112  public function clearLastError() {
113  return $this->backend->clearLastError();
114  }
115 
116  public function modifySimpleRelayEvent( array $event ) {
117  return $this->backend->modifySimpleRelayEvent( $event );
118  }
119 
120  // @codeCoverageIgnoreEnd
121 }
CachedBagOStuff\clearLastError
clearLastError()
Clear the "last error" registry.
Definition: CachedBagOStuff.php:112
HashBagOStuff
Simple store for keeping values in an associative array for the current process.
Definition: HashBagOStuff.php:31
array
the array() calling protocol came about after MediaWiki 1.4rc1.
CachedBagOStuff\unlock
unlock( $key)
Release an advisory lock on a key string.
Definition: CachedBagOStuff.php:104
CachedBagOStuff\getLastError
getLastError()
Get the "last error" registered; clearLastError() should be called manually.
Definition: CachedBagOStuff.php:108
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:2005
CachedBagOStuff\makeKey
makeKey( $class, $component=null)
Make a cache key, scoped to this instance's keyspace.
Definition: CachedBagOStuff.php:89
$params
$params
Definition: styleTest.css.php:40
BagOStuff
interface is intended to be more or less compatible with the PHP memcached client.
Definition: BagOStuff.php:47
HashBagOStuff\hasKey
hasKey( $key)
Does this bag have a non-null value for the given key?
Definition: HashBagOStuff.php:71
CachedBagOStuff\__construct
__construct(BagOStuff $backend, $params=[])
Definition: CachedBagOStuff.php:44
php
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
CachedBagOStuff\setDebug
setDebug( $bool)
Definition: CachedBagOStuff.php:79
CachedBagOStuff\$backend
BagOStuff $backend
Definition: CachedBagOStuff.php:38
CachedBagOStuff\deleteObjectsExpiringBefore
deleteObjectsExpiringBefore( $date, $progressCallback=false)
Delete all objects expiring before a certain date.
Definition: CachedBagOStuff.php:84
CachedBagOStuff\doGet
doGet( $key, $flags=0)
Definition: CachedBagOStuff.php:53
$value
$value
Definition: styleTest.css.php:45
CachedBagOStuff
Wrapper around a BagOStuff that caches data in memory.
Definition: CachedBagOStuff.php:36
CachedBagOStuff\makeGlobalKey
makeGlobalKey( $class, $component=null)
Make a global cache key.
Definition: CachedBagOStuff.php:93
CachedBagOStuff\modifySimpleRelayEvent
modifySimpleRelayEvent(array $event)
Modify a cache update operation array for EventRelayer::notify()
Definition: CachedBagOStuff.php:116
CachedBagOStuff\lock
lock( $key, $timeout=6, $expiry=6, $rclass='')
Acquire an advisory lock on a key string.
Definition: CachedBagOStuff.php:100
BagOStuff\WRITE_CACHE_ONLY
const WRITE_CACHE_ONLY
Definition: BagOStuff.php:90