Memory::flush()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Cache\Memory
5
 *
6
 * Core\Cache Memory Driver.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2015 - http://caffeina.it
11
 */
12
13
namespace Cache;
14
15
class Memory implements Adapter {
16
17
  protected $memory = [];
18
19
    public static function valid(){
20
        return true;
21
    }
22
23
    public function get($key){
24
      if(isset($this->memory[$key])){
25
        if($this->memory[$key][1] && (time() > $this->memory[$key][1])) {
26
          unset($this->memory[$key]);
27
          return null;
28
        }
29
        return $this->memory[$key][0];
30
      }
31
    }
32
33
    public function set($key,$value,$expire=0){
34
      $this->memory[$key] = [$value,$expire?time()+$expire:0];
35
    }
36
37
    public function delete($key){
38
      unset($this->memory[$key]);
39
    }
40
41
    public function exists($key){
42
      return isset($this->memory[$key]) && (!$this->memory[$key][1] || (time() <= $this->memory[$key][1]));
43
    }
44
45
    public function flush(){
46
      $this->memory = [];
47
    }
48
49
    public function inc($key,$value=1){
50
      return isset($this->memory[$key]) ? $this->memory[$key][0] += $value : $this->memory[$key][0] = $value;
51
    }
52
53
    public function dec($key,$value=1){
54
        $this->inc($key,-abs($value));
55
    }
56
}
57