1: | <?php
2: | namespace Opencart\System\Library\Cache;
3: | /**
4: | * Class Mem
5: | *
6: | * @package Opencart\System\Library\Cache
7: | */
8: | class Mem {
9: | /**
10: | * @var \Memcache
11: | */
12: | private \Memcache $memcache;
13: | /**
14: | * @var int
15: | */
16: | private int $expire;
17: |
18: | public const CACHEDUMP_LIMIT = 9999;
19: |
20: | /**
21: | * Constructor
22: | *
23: | * @param int $expire
24: | */
25: | public function __construct(int $expire = 3600) {
26: | $this->expire = $expire;
27: |
28: | $this->memcache = new \Memcache();
29: | $this->memcache->pconnect(CACHE_HOSTNAME, CACHE_PORT);
30: | }
31: |
32: | /**
33: | * Get
34: | *
35: | * @param string $key
36: | *
37: | * @return mixed
38: | */
39: | public function get(string $key) {
40: | return $this->memcache->get(CACHE_PREFIX . $key);
41: | }
42: |
43: | /**
44: | * Set
45: | *
46: | * @param string $key
47: | * @param mixed $value
48: | * @param int $expire
49: | *
50: | * @return void
51: | */
52: | public function set(string $key, $value, int $expire = 0): void {
53: | if (!$expire) {
54: | $expire = $this->expire;
55: | }
56: |
57: | $this->memcache->set(CACHE_PREFIX . $key, $value, MEMCACHE_COMPRESSED, $expire);
58: | }
59: |
60: | /**
61: | * Delete
62: | *
63: | * @param string $key
64: | *
65: | * @return void
66: | */
67: | public function delete(string $key): void {
68: | $this->memcache->delete(CACHE_PREFIX . $key);
69: | }
70: | }
71: |

OpenCart API API documentation generated by ApiGen dev-master