1 | <?php |
||
15 | class CacheFactory { |
||
16 | |||
17 | /** |
||
18 | * @var string|integer |
||
19 | */ |
||
20 | private $mainCacheType; |
||
21 | |||
22 | /** |
||
23 | * @since 2.2 |
||
24 | * |
||
25 | * @param string|integer|null $mainCacheType |
||
26 | */ |
||
27 | 348 | public function __construct( $mainCacheType = null ) { |
|
34 | |||
35 | /** |
||
36 | * @since 2.2 |
||
37 | * |
||
38 | * @return string|integer |
||
39 | */ |
||
40 | 303 | public function getMainCacheType() { |
|
43 | |||
44 | /** |
||
45 | * @since 2.2 |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | 307 | public function getCachePrefix() { |
|
52 | |||
53 | /** |
||
54 | * @since 2.2 |
||
55 | * |
||
56 | * @param string $key |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | 32 | public function getFactboxCacheKey( $key ) { |
|
63 | |||
64 | /** |
||
65 | * @since 2.2 |
||
66 | * |
||
67 | * @param string $key |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 209 | public function getPurgeCacheKey( $key ) { |
|
74 | |||
75 | /** |
||
76 | * @since 2.2 |
||
77 | * |
||
78 | * @param array $cacheOptions |
||
79 | * |
||
80 | * @return stdClass |
||
81 | * @throws RuntimeException |
||
82 | */ |
||
83 | 191 | public function newCacheOptions( array $cacheOptions ) { |
|
91 | |||
92 | /** |
||
93 | * @since 2.2 |
||
94 | * |
||
95 | * @param integer $cacheSize |
||
96 | * |
||
97 | * @return Cache |
||
98 | */ |
||
99 | 342 | public function newFixedInMemoryCache( $cacheSize = 500 ) { |
|
102 | |||
103 | /** |
||
104 | * @since 2.2 |
||
105 | * |
||
106 | * @return Cache |
||
107 | */ |
||
108 | 1 | public function newNullCache() { |
|
111 | |||
112 | /** |
||
113 | * @since 2.2 |
||
114 | * |
||
115 | * @param integer|string $mediaWikiCacheType |
||
116 | * |
||
117 | * @return Cache |
||
118 | */ |
||
119 | 306 | public function newMediaWikiCompositeCache( $mediaWikiCacheType = null ) { |
|
120 | |||
121 | 306 | $compositeCache = OnoiCacheFactory::getInstance()->newCompositeCache( array( |
|
122 | 306 | $this->newFixedInMemoryCache( 500 ), |
|
123 | $this->newMediaWikiCache( $mediaWikiCacheType ) |
||
124 | ) ); |
||
125 | 306 | ||
126 | 306 | return $compositeCache; |
|
127 | 306 | } |
|
128 | |||
129 | /** |
||
130 | 306 | * @since 2.5 |
|
131 | * |
||
132 | * @param integer|string $mediaWikiCacheType |
||
133 | * |
||
134 | * @return Cache |
||
135 | */ |
||
136 | public function newMediaWikiCache( $mediaWikiCacheType = null ) { |
||
137 | |||
138 | $mediaWikiCache = ObjectCache::getInstance( |
||
139 | ( $mediaWikiCacheType === null ? $this->getMainCacheType() : $mediaWikiCacheType ) |
||
140 | ); |
||
141 | |||
142 | 6 | return OnoiCacheFactory::getInstance()->newMediaWikiCache( $mediaWikiCache ); |
|
143 | 6 | } |
|
144 | |||
145 | /** |
||
146 | * @since 2.5 |
||
147 | * |
||
148 | * @param integer|null $cacheType |
||
149 | * |
||
150 | * @return Cache |
||
151 | */ |
||
152 | public function newCacheByType( $cacheType = null ) { |
||
153 | |||
154 | if ( $cacheType === CACHE_NONE || $cacheType === null ) { |
||
155 | return $this->newNullCache(); |
||
156 | } |
||
157 | |||
158 | return $this->newMediaWikiCache( $cacheType ); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @since 2.4 |
||
163 | * |
||
164 | * @param string $namespace |
||
165 | * @param string|integer|null $cacheType |
||
166 | * @param integer $cacheLifetime |
||
167 | * |
||
168 | * @return BlobStore |
||
169 | */ |
||
170 | public function newBlobStore( $namespace, $cacheType = null, $cacheLifetime = 0 ) { |
||
173 | |||
174 | } |
||
175 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: