APCCache   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 2
A save() 0 15 3
A clean() 0 4 1
A remove() 0 4 1
1
<?php
2
/**
3
 * KumbiaPHP web & app Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.
9
 *
10
 * @category   Kumbia
11
 * @package    Cache
12
 * @subpackage Drivers
13
 *
14
 * @copyright  Copyright (c) 2005 - 2019 KumbiaPHP Team (http://www.kumbiaphp.com)
15
 * @license    https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE   New BSD License
16
 */
17
18
/**
19
 * Cacheo de Archivos
20
 *
21
 * @category   Kumbia
22
 * @package    Cache
23
 * @subpackage Drivers
24
 */
25
class APCCache extends Cache
26
{
27
28
    /**
29
     * Carga un elemento cacheado, el apc_fetch puede recibir un array (nuestro cache no)
30
     *
31
     * @param string $id
32
     * @param string $group
33
     * @return string
34
     */
35
    public function get($id, $group='default')
36
    {
37
        $this->_id = $id;
38
        $this->_group = $group;
39
40
        $data = apc_fetch("$id.$group");
41
        if ($data !== FALSE) {
42
            return $data;
43
        }
44
    }
45
46
    /**
47
     * Guarda un elemento en la cache con nombre $id y valor $value
48
     *
49
     * @param string $id
50
     * @param string $group
51
     * @param string $value
52
     * @param int $lifetime tiempo de vida en forma timestamp de unix
53
     * @return boolean
54
     */
55
    public function save($id, $group, $value, $lifetime)
56
    {
57
        if (!$id) {
58
            $id = $this->_id;
59
            $group = $this->_group;
60
        }
61
62
        if ($lifetime) {
63
            $lifetime = strtotime($lifetime) - time();
64
        } else {
65
            $lifetime = '0';
66
        }
67
68
        return apc_store("$id.$group", $value, $lifetime);
69
    }
70
71
    /**
72
     * Limpia la cache, con APC se limpia TODA no sólo el grupo
73
     *
74
     * @param string $group No se usa con APC
75
     * @return boolean
76
     */
77
    public function clean($group=false)
78
    {
79
        return apc_clear_cache('user');
80
    }
81
82
    /**
83
     * Elimina un elemento de la cache
84
     *
85
     * @param string $id
86
     * @param string $group
87
     * @return boolean
88
     */
89
    public function remove($id, $group='default')
90
    {
91
        return apc_delete("$id.$group");
92
    }
93
94
}