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