-
Notifications
You must be signed in to change notification settings - Fork 0
/
CacheAdapter.php
54 lines (48 loc) · 1.04 KB
/
CacheAdapter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Class CacheAdapter
* Когда нибуть у нас будет нормальный эеш...
*/
class CacheAdapter
{
/**
* @var array
*/
static private $data = array();
private $sessionId = '0000sessionForCache0000';
/**
* CacheAdapter constructor.
*/
public function __construct()
{
global $db;
$data = $db->fetch('select sessions_data from sessions where sessions_id = "' . $this->sessionId . '"', 0);
$data = json_decode($data, true);
self::$data = ($data) ? $data : array();
}
public function __destruct()
{
global $db;
$data = array('sessions_data' => json_encode(self::$data), 'sessions_id' => $this->sessionId);
$db->insert('sessions', $data, array_keys($data), true);
}
/**
* @param string $key
*
* @return bool|mixed
*/
public function get($key)
{
return (array_key_exists($key, self::$data)) ? self::$data[$key] : false;
}
/**
* @param string $key
* @param mixed $value
*
* @return void
*/
public function set($key, $value)
{
self::$data[$key] = $value;
}
}