1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Manage Cache by Memory |
5
|
|
|
* |
6
|
|
|
* @category lib |
7
|
|
|
* @package lib\Cache |
8
|
|
|
* @author Judicaël Paquet <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
10
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
11
|
|
|
* @version Release: 1.0.0 |
12
|
|
|
* @filesource https://github.com/las93/venus2 |
13
|
|
|
* @link https://github.com/las93 |
14
|
|
|
* @since 1.0 |
15
|
|
|
*/ |
16
|
|
|
namespace Venus\lib\Cache; |
17
|
|
|
use \Venus\lib\Cache\CacheInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This class manage the Cache by Memory |
21
|
|
|
* |
22
|
|
|
* @category lib |
23
|
|
|
* @package lib\Cache |
24
|
|
|
* @author Judicaël Paquet <[email protected]> |
25
|
|
|
* @copyright Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93) |
26
|
|
|
* @license https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël |
27
|
|
|
* @version Release: 1.0.0 |
28
|
|
|
* @filesource https://github.com/las93/venus2 |
29
|
|
|
* @link https://github.com/las93 |
30
|
|
|
* @since 1.0 |
31
|
|
|
*/ |
32
|
|
|
class Memory implements CacheInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* A static variable to keep the cache |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private static $_aMemories = array(); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* set a value |
42
|
|
|
* |
43
|
|
|
* @access public |
44
|
|
|
* @param string $sName name of the session |
45
|
|
|
* @param mixed $mValue value of this sesion var |
46
|
|
|
* @param int $iFlag unused |
47
|
|
|
* @param int $iExpire expiration of cache |
48
|
|
|
* @return \Venus\lib\Cache\Apc |
49
|
|
|
*/ |
50
|
|
|
public function set(string $sName, $mValue, int $iFlag = 0, int $iExpire = 0) |
51
|
|
|
{ |
52
|
|
|
self::$_aMemories[$sName] = $mValue; |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* get a value |
58
|
|
|
* |
59
|
|
|
* @access public |
60
|
|
|
* @param string $sName name of the session |
61
|
|
|
* @param int $iFlags flags |
62
|
|
|
* @param int $iTimeout expiration of cache |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
|
|
public function get(string $sName, int &$iFlags = null, int $iTimeout = 0) |
66
|
|
|
{ |
67
|
|
|
return self::$_aMemories[$sName]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* delete a value |
72
|
|
|
* |
73
|
|
|
* @access public |
74
|
|
|
* @param string $sName name of the session |
75
|
|
|
* @return true |
76
|
|
|
*/ |
77
|
|
|
public function delete(string $sName) |
78
|
|
|
{ |
79
|
|
|
unset(self::$_aMemories[$sName]); |
80
|
|
|
return true; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* flush the cache |
85
|
|
|
* |
86
|
|
|
* @access public |
87
|
|
|
* @return mixed |
88
|
|
|
*/ |
89
|
|
|
public function flush() |
90
|
|
|
{ |
91
|
|
|
return self::$_aMemories = array(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|