1<?php
2
3
4namespace ComboStrap;
5
6use dokuwiki\Cache\CacheInstructions;
7
8/**
9 * Class BarCache
10 * @package ComboStrap
11 *
12 * See {@link CacheByLogicalKey} for explanation
13 *
14 * Adapted from {@link CacheInstructions}
15 * because the storage is an array and the storage process is cached in the code function
16 * {@link CacheInstructionsByLogicalKey::retrieveCache()} and
17 * {@link CacheInstructionsByLogicalKey::storeCache()}
18 */
19class CacheInstructionsByLogicalKey extends CacheByLogicalKey
20{
21    public $pageObject;
22
23    public $mode;
24
25    /**
26     * BarCache constructor.
27     *
28     * @param $pageObject - logical id
29     */
30    public function __construct($pageObject)
31    {
32        $this->pageObject = $pageObject;
33        $this->mode = "i";
34
35        parent::__construct($pageObject, $this->mode);
36
37    }
38
39    /**
40     * retrieve the cached data
41     *
42     * @param bool $clean true to clean line endings, false to leave line endings alone
43     * @return  array          cache contents
44     */
45    public function retrieveCache($clean = true)
46    {
47        $contents = io_readFile($this->getCacheFile(), false);
48        return !empty($contents) ? unserialize($contents) : array();
49    }
50
51    /**
52     * cache $instructions
53     *
54     * @param array $instructions the instruction to be cached
55     * @return  bool                  true on success, false otherwise
56     * @noinspection PhpParameterNameChangedDuringInheritanceInspection
57     */
58    public function storeCache($instructions): bool
59    {
60        if ($this->_nocache) {
61            return false;
62        }
63
64        return io_saveFile($this->getCacheFile(), serialize($instructions));
65    }
66
67
68}
69