Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CachedMessageIndex
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 retrieve
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
 store
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare ( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\MessageLoading;
5
6use BagOStuff;
7use ObjectCache;
8
9/**
10 * Storage on the object cache.
11 *
12 * This can be faster than DatabaseMessageIndex, but it doesn't
13 * provide random access, and the data is not guaranteed to be persistent.
14 *
15 * This is unlikely to be the best backend for you, so don't use it.
16 * @deprecated since MLEB 2024.04
17 */
18class CachedMessageIndex extends MessageIndex {
19    private $key = 'translate-messageindex';
20    private BagOStuff $cache;
21    private ?array $index = null;
22
23    protected function __construct() {
24        parent::__construct();
25        wfDeprecated( __CLASS__, 'MLEB 2024.04', 'Translate' );
26        $this->cache = ObjectCache::getInstance( CACHE_ANYTHING );
27    }
28
29    public function retrieve( bool $readLatest = false ): array {
30        if ( $this->index !== null ) {
31            return $this->index;
32        }
33
34        $key = $this->cache->makeKey( $this->key );
35        $data = $this->cache->get( $key );
36        if ( is_array( $data ) ) {
37            $this->index = $data;
38        } else {
39            $this->index = $this->rebuild();
40        }
41
42        return $this->index;
43    }
44
45    protected function store( array $array, array $diff ): void {
46        $key = $this->cache->makeKey( $this->key );
47        $this->cache->set( $key, $array );
48
49        $this->index = $array;
50    }
51}