| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Edit; |
| 4 |
|
| 5 |
use MediaWiki\Json\JsonCodec; |
| 6 |
use MediaWiki\Parser\Parsoid\PageBundleJsonTrait; |
| 7 |
use Wikimedia\ObjectCache\BagOStuff; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class SimpleParsoidOutputStash implements ParsoidOutputStash { |
| 14 |
use PageBundleJsonTrait; |
| 15 |
|
| 16 |
public function __construct( |
| 17 |
private JsonCodec $jsonCodec, |
| 18 |
|
| 19 |
private BagOStuff $bagOfStuff, |
| 20 |
|
| 21 |
private int $duration, |
| 22 |
) { |
| 23 |
} |
| 24 |
|
| 25 |
private function makeCacheKey( ParsoidRenderID $renderId ): string { |
| 26 |
return $this->bagOfStuff->makeKey( 'ParsoidOutputStash', $renderId->getKey() ); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public function set( ParsoidRenderID $renderId, SelserContext $selserContext ): bool { |
| 39 |
$jsonic = $this->jsonCodec->toJsonArray( |
| 40 |
$selserContext, SelserContext::class |
| 41 |
); |
| 42 |
$key = $this->makeCacheKey( $renderId ); |
| 43 |
return $this->bagOfStuff->set( $key, $jsonic, $this->duration ); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function get( ParsoidRenderID $renderId ): ?SelserContext { |
| 56 |
$key = $this->makeCacheKey( $renderId ); |
| 57 |
$jsonic = $this->bagOfStuff->get( $key ) ?? []; |
| 58 |
|
| 59 |
if ( !is_array( $jsonic ) ) { |
| 60 |
|
| 61 |
|
| 62 |
return null; |
| 63 |
} |
| 64 |
if ( !isset( $jsonic['pb'] ) ) { |
| 65 |
return null; |
| 66 |
} |
| 67 |
return $this->jsonCodec->newFromJsonArray( |
| 68 |
$jsonic, SelserContext::class |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
} |