Failed Conditions
Push — refactorCachePSR2 ( 0db577 )
by Michael
02:54
created

CacheInstructions::storeCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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