1 | <?php |
||
23 | class LanguageTargetLinksCache { |
||
24 | |||
25 | /** |
||
26 | * @var Cache |
||
27 | */ |
||
28 | private $cache; |
||
29 | |||
30 | /** |
||
31 | * @var CacheKeyProvider |
||
32 | */ |
||
33 | private $cacheKeyProvider; |
||
34 | |||
35 | /** |
||
36 | * The current page language cache strategy is to store language by page |
||
37 | * into a blob value to avoid high cache fragmentation and keep the cache |
||
38 | * lookup performant on generated category/search lists. |
||
39 | * |
||
40 | * Whether the blob language-page strategy has a considerable performance draw |
||
41 | * back on large lists of stored language-page pairs has yet to be determined |
||
42 | * but it will be fairly easy to switch to a single language-page strategy |
||
43 | * if necessary. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $pageLanguageCacheStrategy = 'single'; |
||
48 | |||
49 | /** |
||
50 | * @since 1.0 |
||
51 | * |
||
52 | * @param Cache $cache |
||
53 | * @param CacheKeyProvider $cacheKeyProvider |
||
54 | */ |
||
55 | 18 | public function __construct( Cache $cache, CacheKeyProvider $cacheKeyProvider ) { |
|
59 | |||
60 | /** |
||
61 | * @since 1.0 |
||
62 | * |
||
63 | * @param string $pageLanguageCacheStrategy |
||
64 | */ |
||
65 | 16 | public function setPageLanguageCacheStrategy( $pageLanguageCacheStrategy ) { |
|
68 | |||
69 | /** |
||
70 | * @since 1.0 |
||
71 | * |
||
72 | * @param Title $title |
||
73 | * |
||
74 | * @param boolean|string |
||
75 | */ |
||
76 | 12 | public function getPageLanguageFromCache( Title $title ) { |
|
79 | |||
80 | /** |
||
81 | * @since 1.0 |
||
82 | * |
||
83 | * @param Title $title |
||
84 | * @param string $languageCode |
||
85 | */ |
||
86 | 10 | public function pushPageLanguageToCache( Title $title, $languageCode ) { |
|
87 | |||
88 | $normalizedLanguageTargetLink = array( |
||
89 | 10 | $languageCode => $title->getPrefixedText() |
|
90 | 10 | ); |
|
91 | |||
92 | 10 | $this->save( $normalizedLanguageTargetLink ); |
|
93 | 10 | } |
|
94 | |||
95 | /** |
||
96 | * @since 1.0 |
||
97 | * |
||
98 | * @param InterlanguageLink $interlanguageLink |
||
99 | * |
||
100 | * @return boolean|array |
||
101 | */ |
||
102 | 20 | public function getLanguageTargetLinksFromCache( InterlanguageLink $interlanguageLink ) { |
|
123 | |||
124 | /** |
||
125 | * @since 1.0 |
||
126 | * |
||
127 | * @param InterlanguageLink $interlanguageLink |
||
128 | * @param array $languageTargetLinks |
||
129 | */ |
||
130 | 21 | public function saveLanguageTargetLinksToCache( InterlanguageLink $interlanguageLink, array $languageTargetLinks ) { |
|
154 | |||
155 | /** |
||
156 | * @since 1.0 |
||
157 | * |
||
158 | * @param DIWikiPage[] $linkReferences |
||
159 | */ |
||
160 | 14 | public function deleteLanguageTargetLinksFromCache( array $linkReferences ) { |
|
187 | |||
188 | /** |
||
189 | * @since 1.0 |
||
190 | * |
||
191 | * @param Title $title |
||
192 | */ |
||
193 | 12 | public function deletePageLanguageForTargetFromCache( Title $title ) { |
|
196 | |||
197 | 12 | private function fetch( Title $title ) { |
|
212 | |||
213 | 22 | private function save( array $normalizedLanguageTargetLinks ) { |
|
238 | |||
239 | 12 | private function delete( Title $title ) { |
|
255 | |||
256 | 7 | private function getPageLanguageCacheBlob() { |
|
268 | |||
269 | } |
||
270 |