1 | <?php |
||
17 | class JsonLdDataValueFormatterCache { |
||
18 | |||
19 | const CACHE_ID_PREFIX = 'ppp-wd-jsonld-dv-'; |
||
20 | |||
21 | const CACHE_LIFE_TIME = 86400; |
||
22 | |||
23 | /** |
||
24 | * @var Cache |
||
25 | */ |
||
26 | private $cache; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $name; |
||
32 | |||
33 | /** |
||
34 | * @param Cache $cache |
||
35 | */ |
||
36 | 4 | public function __construct(Cache $cache, $name) { |
|
40 | |||
41 | /** |
||
42 | * @param DataValue $dataValue |
||
43 | * @return stdClass |
||
44 | */ |
||
45 | 2 | public function fetch(DataValue $dataValue) { |
|
46 | 2 | $result = $this->cache->fetch($this->getCacheId($dataValue)); |
|
47 | |||
48 | 2 | if($result === false) { |
|
49 | 1 | throw new OutOfBoundsException('The search is not in the cache.'); |
|
50 | } |
||
51 | |||
52 | 1 | return $result; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param DataValue $dataValue |
||
57 | * @return bool |
||
58 | */ |
||
59 | 2 | public function contains(DataValue $dataValue) { |
|
62 | |||
63 | /** |
||
64 | * @param DataValue $dataValue |
||
65 | * @param stdClass $jsonLd |
||
66 | */ |
||
67 | 3 | public function save(DataValue $dataValue, stdClass $jsonLd) { |
|
68 | 3 | if(!$this->cache->save( |
|
69 | 3 | $this->getCacheId($dataValue), |
|
70 | 3 | $jsonLd, |
|
71 | self::CACHE_LIFE_TIME |
||
72 | 3 | )) { |
|
73 | throw new RuntimeException('The cache failed to save.'); |
||
74 | } |
||
75 | 3 | } |
|
76 | |||
77 | 4 | private function getCacheId(DataValue $dataValue) { |
|
80 | } |
||
81 |