MediaWiki REL1_33
DependencyWrapper.php
Go to the documentation of this file.
1<?php
31 private $value;
33 private $deps;
34
40 function __construct( $value = false, $deps = [] ) {
41 $this->value = $value;
42
43 if ( !is_array( $deps ) ) {
44 $deps = [ $deps ];
45 }
46
47 $this->deps = $deps;
48 }
49
55 function isExpired() {
56 foreach ( $this->deps as $dep ) {
57 if ( $dep->isExpired() ) {
58 return true;
59 }
60 }
61
62 return false;
63 }
64
69 function initialiseDeps() {
70 foreach ( $this->deps as $dep ) {
71 $dep->loadDependencyValues();
72 }
73 }
74
79 function getValue() {
80 return $this->value;
81 }
82
90 function storeToCache( $cache, $key, $expiry = 0 ) {
91 $this->initialiseDeps();
92 $cache->set( $key, $this, $expiry );
93 }
94
112 static function getValueFromCache( $cache, $key, $expiry = 0, $callback = false,
113 $callbackParams = [], $deps = []
114 ) {
115 $obj = $cache->get( $key );
116
117 if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) {
118 $value = $obj->value;
119 } elseif ( $callback ) {
120 $value = $callback( ...$callbackParams );
121 # Cache the newly-generated value
122 $wrapper = new DependencyWrapper( $value, $deps );
123 $wrapper->storeToCache( $cache, $key, $expiry );
124 } else {
125 $value = null;
126 }
127
128 return $value;
129 }
130}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
This class stores an arbitrary value along with its dependencies.
__construct( $value=false, $deps=[])
initialiseDeps()
Initialise dependency values in preparation for storing.
static getValueFromCache( $cache, $key, $expiry=0, $callback=false, $callbackParams=[], $deps=[])
Attempt to get a value from the cache.
CacheDependency[] $deps
storeToCache( $cache, $key, $expiry=0)
Store the wrapper to a cache.
getValue()
Get the user-defined value.
isExpired()
Returns true if any of the dependencies have expired.
$cache
Definition mcc.php:33