1 | <?php |
||
15 | class MediaWikiCache implements Cache { |
||
16 | |||
17 | /** |
||
18 | * @var BagOStuff |
||
19 | */ |
||
20 | private $cache = null; |
||
21 | |||
22 | /** |
||
23 | * @note MediaWiki's BagOStuff doesn't know any has/contains function therefore |
||
24 | * we need to use an internal array the fetch and temporarily store the results |
||
25 | * to ensure no expensive lookups occur for the same key |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | private $inMemoryCache = array(); |
||
30 | |||
31 | /** |
||
32 | * @var integer |
||
33 | */ |
||
34 | private $cacheInserts = 0; |
||
35 | |||
36 | /** |
||
37 | * @var integer |
||
38 | */ |
||
39 | private $cacheDeletes = 0; |
||
40 | |||
41 | /** |
||
42 | * @var integer |
||
43 | */ |
||
44 | private $cacheHits = 0; |
||
45 | |||
46 | /** |
||
47 | * @var integer |
||
48 | */ |
||
49 | private $cacheMisses = 0; |
||
50 | |||
51 | /** |
||
52 | * @since 1.0 |
||
53 | * |
||
54 | * @param BagOStuff $cache |
||
55 | */ |
||
56 | 6 | public function __construct( BagOStuff $cache ) { |
|
59 | |||
60 | /** |
||
61 | * @since 1.0 |
||
62 | * |
||
63 | * {@inheritDoc} |
||
64 | */ |
||
65 | 1 | public function fetch( $id ) { |
|
66 | |||
67 | 1 | if ( $this->contains( $id ) ) { |
|
68 | 1 | $this->cacheHits++; |
|
69 | 1 | return $this->inMemoryCache[ $id ]; |
|
70 | } |
||
71 | |||
72 | $this->cacheMisses++; |
||
73 | return false; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @since 1.0 |
||
78 | * |
||
79 | * {@inheritDoc} |
||
80 | */ |
||
81 | 4 | public function contains( $id ) { |
|
91 | |||
92 | /** |
||
93 | * @since 1.0 |
||
94 | * |
||
95 | * {@inheritDoc} |
||
96 | */ |
||
97 | 3 | public function save( $id, $data, $ttl = 0 ) { |
|
102 | |||
103 | /** |
||
104 | * @since 1.0 |
||
105 | * |
||
106 | * {@inheritDoc} |
||
107 | */ |
||
108 | 3 | public function delete( $id ) { |
|
113 | |||
114 | /** |
||
115 | * @since 1.0 |
||
116 | * |
||
117 | * {@inheritDoc} |
||
118 | */ |
||
119 | 1 | public function getStats() { |
|
127 | |||
128 | /** |
||
129 | * @since 1.2 |
||
130 | * |
||
131 | * {@inheritDoc} |
||
132 | */ |
||
133 | 1 | public function getName() { |
|
136 | |||
137 | } |
||
138 |