LocalCacheTrait::hasLocalCache()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Shared
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Shared\Cache;
16
17
/**
18
 * LocalCacheTrait
19
 *
20
 * Provides a local/class level cache support
21
 *
22
 * @package Phossa2\Shared
23
 * @author  Hong Zhang <[email protected]>
24
 * @version 2.0.8
25
 * @since   2.0.8 added
26
 */
27
trait LocalCacheTrait
28
{
29
    /**
30
     * a local cache
31
     *
32
     * @var    array
33
     * @access private
34
     */
35
    private $local_cache = [];
36
37
    /**
38
     * Clear local cache
39
     *
40
     * @return $this
41
     * @access protected
42
     */
43
    protected function clearLocalCache()
44
    {
45
        $this->local_cache = [];
46
        return $this;
47
    }
48
49
    /**
50
     * has cached ?
51
     *
52
     * @param  string $name
53
     * @return bool
54
     * @access protected
55
     */
56
    protected function hasLocalCache(/*# strign */ $name)/*# : bool */
57
    {
58
        return isset($this->local_cache[$name]);
59
    }
60
61
    /**
62
     * get the cached value
63
     *
64
     * @param  string $name
65
     * @return mixed
66
     * @access protected
67
     */
68
    protected function getLocalCache(/*# strign */ $name)
69
    {
70
        return $this->local_cache[$name];
71
    }
72
73
    /**
74
     * set the cache
75
     *
76
     * @param  string $name
77
     * @param  mixed $value
78
     * @return $this
79
     * @access protected
80
     */
81
    protected function setLocalCache(/*# strign */ $name, $value)
82
    {
83
        $this->local_cache[$name] = $value;
84
        return $this;
85
    }
86
}
87