1: | <?php |
2: | |
3: | namespace ngatngay\session\storage; |
4: | |
5: | class apcu implements \SessionHandlerInterface |
6: | { |
7: | private string $prefix; |
8: | private int $ttl; |
9: | |
10: | public function __construct($prefix = 'sess_', $ttl = 86400) |
11: | { |
12: | $this->prefix = $prefix; |
13: | $this->ttl = $ttl; |
14: | } |
15: | |
16: | #[\ReturnTypeWillChange] |
17: | public function close() |
18: | { |
19: | return true; |
20: | } |
21: | |
22: | #[\ReturnTypeWillChange] |
23: | public function destroy($id) |
24: | { |
25: | $key = $this->prefix . $id; |
26: | return apcu_delete($key); |
27: | } |
28: | |
29: | #[\ReturnTypeWillChange] |
30: | public function gc($max_lifetime) |
31: | { |
32: | return 1; |
33: | } |
34: | |
35: | #[\ReturnTypeWillChange] |
36: | public function open($path, $name) |
37: | { |
38: | return true; |
39: | } |
40: | |
41: | #[\ReturnTypeWillChange] |
42: | public function read($id) |
43: | { |
44: | $key = $this->prefix . $id; |
45: | return apcu_exists($key) ? apcu_fetch($key) : ''; |
46: | } |
47: | |
48: | #[\ReturnTypeWillChange] |
49: | public function write($id, $data) |
50: | { |
51: | $key = $this->prefix . $id; |
52: | return apcu_store($key, $data, $this->ttl); |
53: | } |
54: | } |