From 059e0d95d0c28bc5060e87e146eaf7411f51bf90 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Thu, 27 Apr 2023 03:47:30 +0300 Subject: skeleton commit; based on an anom project --- core/classes/cache/Cache_interface.php | 34 +++++++++++++ core/classes/cache/FileCache.php | 93 ++++++++++++++++++++++++++++++++++ core/classes/cache/MemcachedCache.php | 37 ++++++++++++++ core/classes/cache/RedisCache.php | 69 +++++++++++++++++++++++++ 4 files changed, 233 insertions(+) create mode 100644 core/classes/cache/Cache_interface.php create mode 100644 core/classes/cache/FileCache.php create mode 100644 core/classes/cache/MemcachedCache.php create mode 100644 core/classes/cache/RedisCache.php (limited to 'core/classes/cache') diff --git a/core/classes/cache/Cache_interface.php b/core/classes/cache/Cache_interface.php new file mode 100644 index 0000000..7c49789 --- /dev/null +++ b/core/classes/cache/Cache_interface.php @@ -0,0 +1,34 @@ + $data[0]) { + + // Unlinking + unlink($filename); + return false; + + } + + return $data[1]; + } + + + public function flush(int $olderThan = 0) + { + return false; // reply false until implementation + } + +} diff --git a/core/classes/cache/MemcachedCache.php b/core/classes/cache/MemcachedCache.php new file mode 100644 index 0000000..c89d86a --- /dev/null +++ b/core/classes/cache/MemcachedCache.php @@ -0,0 +1,37 @@ +addServer(\MEMCACHE_HOST, 11211); + + $mc->set($hashkey, $data, $ttl); + } + + + public function get($key) + { + $hashkey = md5($key); + + $mc = new Memcached(); + $mc->addServer(\MEMCACHE_HOST, 11211); + + return $mc->get($hashkey); + + } + + public function flush($olderThan = 0) + { + return false; + } + +} \ No newline at end of file diff --git a/core/classes/cache/RedisCache.php b/core/classes/cache/RedisCache.php new file mode 100644 index 0000000..ec50f08 --- /dev/null +++ b/core/classes/cache/RedisCache.php @@ -0,0 +1,69 @@ + \REDIS_HOST + ]); + return $redis->set($key, $serialized, 'EX', $ttl); + + } catch (Exception $e) { + // ... + } + } + + + /** get + * fetch previously stored $data under label $key + * return $data (or false) + */ + public function get($key) + { + + try { + + $redis = new \Predis\Client([ + 'host' => \REDIS_HOST + ]); + + if ($redis->exists($key)) { + return unserialize($redis->get($key)); + + } else { + return false; + } + + } catch (Exception $e) { + // ... + } + + } + + + /** flush + * --- not umplemented yet; may not needed + */ + public function flush($olderThan = 0) + { + return false; // until implementation + } + +} \ No newline at end of file -- cgit v1.2.3