10db5771eSMichael Große<?php 20db5771eSMichael Große 30db5771eSMichael Großenamespace dokuwiki\Cache; 40db5771eSMichael Große 50db5771eSMichael Große/** 60db5771eSMichael Große * Caching of parser instructions 70db5771eSMichael Große */ 8*a95427a5SAndreas Gohrclass CacheInstructions extends CacheParser 90db5771eSMichael Große{ 100db5771eSMichael Große /** 110db5771eSMichael Große * @param string $id page id 120db5771eSMichael Große * @param string $file source file for cache 130db5771eSMichael Große */ 140db5771eSMichael Große public function __construct($id, $file) 150db5771eSMichael Große { 160db5771eSMichael Große parent::__construct($id, $file, 'i'); 170db5771eSMichael Große } 180db5771eSMichael Große 190db5771eSMichael Große /** 200db5771eSMichael Große * retrieve the cached data 210db5771eSMichael Große * 220db5771eSMichael Große * @param bool $clean true to clean line endings, false to leave line endings alone 230db5771eSMichael Große * @return array cache contents 240db5771eSMichael Große */ 250db5771eSMichael Große public function retrieveCache($clean = true) 260db5771eSMichael Große { 270db5771eSMichael Große $contents = io_readFile($this->cache, false); 28*a95427a5SAndreas Gohr return empty($contents) ? [] : unserialize($contents); 290db5771eSMichael Große } 300db5771eSMichael Große 310db5771eSMichael Große /** 320db5771eSMichael Große * cache $instructions 330db5771eSMichael Große * 340db5771eSMichael Große * @param array $instructions the instruction to be cached 350db5771eSMichael Große * @return bool true on success, false otherwise 360db5771eSMichael Große */ 370db5771eSMichael Große public function storeCache($instructions) 380db5771eSMichael Große { 39b4b0b31bSMichael Große if ($this->_nocache) { 400db5771eSMichael Große return false; 410db5771eSMichael Große } 420db5771eSMichael Große 43033eb35bSkalenpw return io_saveFile($this->cache, serialize($instructions)); 440db5771eSMichael Große } 450db5771eSMichael Große} 46