Index: trunk/phase3/includes/objectcache/SqlBagOStuff.php |
— | — | @@ -18,17 +18,28 @@ |
19 | 19 | var $db; |
20 | 20 | var $serverInfo; |
21 | 21 | var $lastExpireAll = 0; |
| 22 | + var $purgePeriod = 100; |
22 | 23 | |
23 | 24 | /** |
24 | 25 | * Constructor. Parameters are: |
25 | 26 | * - server: A server info structure in the format required by each |
26 | 27 | * element in $wgDBServers. |
| 28 | + * |
| 29 | + * - purgePeriod: The average number of object cache requests in between |
| 30 | + * garbage collection operations, where expired entries |
| 31 | + * are removed from the database. Or in other words, the |
| 32 | + * reciprocal of the probability of purging on any given |
| 33 | + * request. If this is set to zero, purging will never be |
| 34 | + * done. |
27 | 35 | */ |
28 | 36 | public function __construct( $params ) { |
29 | 37 | if ( isset( $params['server'] ) ) { |
30 | 38 | $this->serverInfo = $params['server']; |
31 | 39 | $this->serverInfo['load'] = 1; |
32 | 40 | } |
| 41 | + if ( isset( $params['purgePeriod'] ) ) { |
| 42 | + $this->purgePeriod = intval( $params['purgePeriod'] ); |
| 43 | + } |
33 | 44 | } |
34 | 45 | |
35 | 46 | /** |
— | — | @@ -213,15 +224,20 @@ |
214 | 225 | } |
215 | 226 | |
216 | 227 | protected function garbageCollect() { |
217 | | - /* Ignore 99% of requests */ |
218 | | - if ( !mt_rand( 0, 100 ) ) { |
219 | | - $now = time(); |
220 | | - /* Avoid repeating the delete within a few seconds */ |
221 | | - if ( $now > ( $this->lastExpireAll + 1 ) ) { |
222 | | - $this->lastExpireAll = $now; |
223 | | - $this->expireAll(); |
224 | | - } |
| 228 | + if ( !$this->purgePeriod ) { |
| 229 | + // Disabled |
| 230 | + return; |
225 | 231 | } |
| 232 | + // Only purge on one in every $this->purgePeriod requests. |
| 233 | + if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) { |
| 234 | + return; |
| 235 | + } |
| 236 | + $now = time(); |
| 237 | + // Avoid repeating the delete within a few seconds |
| 238 | + if ( $now > ( $this->lastExpireAll + 1 ) ) { |
| 239 | + $this->lastExpireAll = $now; |
| 240 | + $this->expireAll(); |
| 241 | + } |
226 | 242 | } |
227 | 243 | |
228 | 244 | public function expireAll() { |