xref: /dokuwiki/inc/Cache/CacheInstructions.php (revision b73ece99c18919754d993a1d1f5cb27140555705)
1<?php
2
3namespace dokuwiki\Cache;
4
5/**
6 * Caching of parser instructions
7 */
8class CacheInstructions extends CacheParser
9{
10    /**
11     * @param string $id page id
12     * @param string $file source file for cache
13     * @param string|null $syntax syntax flavour the file is parsed under;
14     *     see CacheParser::__construct()
15     */
16    public function __construct($id, $file, $syntax = null)
17    {
18        parent::__construct($id, $file, 'i', $syntax);
19    }
20
21    /**
22     * retrieve the cached data
23     *
24     * @param   bool $clean true to clean line endings, false to leave line endings alone
25     * @return  array          cache contents
26     */
27    public function retrieveCache($clean = true)
28    {
29        $contents = io_readFile($this->cache, false);
30        return empty($contents) ? [] : unserialize($contents);
31    }
32
33    /**
34     * cache $instructions
35     *
36     * @param   array $instructions the instruction to be cached
37     * @return  bool                  true on success, false otherwise
38     */
39    public function storeCache($instructions)
40    {
41        if ($this->_nocache) {
42            return false;
43        }
44
45        return io_saveFile($this->cache, serialize($instructions));
46    }
47}
48