From 895a3dd6a2ff3a7ad72e49d1a76ffd8b4cc426ad Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 13 Aug 2023 12:04:26 +0300 Subject: [PATCH 1/6] update readme --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/README.md b/README.md index 3f2d90b..52d349c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,58 @@ # cache-php Cache tools for PHP applications + +### Memory + +Extends [PHP memcached](https://www.php.net/manual/en/book.memcached.php) + +#### Init + +``` +$memory = new Yggverse\Cache\Memory( + + 'localhost, // memcached server host, localhost by default + 11211, // memcached server port, 11211 by default + + 'my_app', // application namespace + 3600 // cache time offset by default +); +``` + +#### Supported methods + +##### Memory::set + +##### Memory::delete + +##### Memory::flush + +##### Memory::get + +##### Memory::getByValueCallback + +Return cached or cache new value of plain value callback + +``` + $value = $memory->getByValueCallback( + 'key_name', // string, unique key name + 'value', // mixed, plain value + 3600, // optional, cache timeout offset for this value + ); +``` + +##### Memory::getByMethodCallback + +Return cached or cache new value of object method callback + +``` + $value = $memory->getByMethodCallback( + $class_object, // object of method class + 'method_name', // object method name + [ + $method_attribute_1, // optional, array of attributes callback method requires + $method_attribute_2, + ... + ] + 3600, // optional, cache timeout offset for this value + ); +``` \ No newline at end of file From e6903cc64086594d9d18b1699781b56ecb58e72f Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 13 Aug 2023 12:18:44 +0300 Subject: [PATCH 2/6] remove current timestamp prefix from timeout definition --- README.md | 16 ++++++++-------- src/Memory.php | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 52d349c..23e1c6b 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ Extends [PHP memcached](https://www.php.net/manual/en/book.memcached.php) ``` $memory = new Yggverse\Cache\Memory( - 'localhost, // memcached server host, localhost by default - 11211, // memcached server port, 11211 by default + 'localhost, // memcached server host, localhost by default + 11211, // memcached server port, 11211 by default - 'my_app', // application namespace - 3600 // cache time offset by default + 'my_app', // application namespace + 3600 + time() // cache time by default ); ``` @@ -34,9 +34,9 @@ Return cached or cache new value of plain value callback ``` $value = $memory->getByValueCallback( - 'key_name', // string, unique key name - 'value', // mixed, plain value - 3600, // optional, cache timeout offset for this value + 'key_name', // string, unique key name + 'value', // mixed, plain value + 3600 + time(), // optional, cache timeout for this value ); ``` @@ -53,6 +53,6 @@ Return cached or cache new value of object method callback $method_attribute_2, ... ] - 3600, // optional, cache timeout offset for this value + 3600 + time(), // optional, cache timeout for this value ); ``` \ No newline at end of file diff --git a/src/Memory.php b/src/Memory.php index 5f06f29..38d93f8 100644 --- a/src/Memory.php +++ b/src/Memory.php @@ -40,7 +40,7 @@ class Memory { ] ); - return $this->_memcached->set($key, $value, ($timeout ? $timeout : $this->_timeout) + time()); + return $this->_memcached->set($key, $value, ($timeout ? $timeout : $this->_timeout)); } public function delete(string $key) : bool @@ -70,7 +70,7 @@ class Memory { } else { - if (true === $this->_memcached->set($key, $value, ($timeout ? $timeout : $this->_timeout) + time())) + if (true === $this->_memcached->set($key, $value, ($timeout ? $timeout : $this->_timeout))) { return $value; } @@ -106,7 +106,7 @@ class Memory { $arguments ); - if (true === $this->_memcached->set($key, $value, ($timeout ? $timeout : $this->_timeout) + time())) + if (true === $this->_memcached->set($key, $value, ($timeout ? $timeout : $this->_timeout))) { return $value; } From b2111aee02e216bd846caaeacbc5e74ce81952aa Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 9 Oct 2023 04:50:52 +0300 Subject: [PATCH 3/6] fix namespace --- src/Memory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Memory.php b/src/Memory.php index 38d93f8..83817be 100644 --- a/src/Memory.php +++ b/src/Memory.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace YGGverse\Cache; +namespace Yggverse\Cache; class Memory { From bbbf224979828551dadaa24b6cb356a531bde484 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 24 Jan 2024 04:20:29 +0200 Subject: [PATCH 4/6] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 23e1c6b..2a042d9 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ Extends [PHP memcached](https://www.php.net/manual/en/book.memcached.php) #### Init ``` -$memory = new Yggverse\Cache\Memory( +$memory = new \Yggverse\Cache\Memory( - 'localhost, // memcached server host, localhost by default + 'localhost', // memcached server host, localhost by default 11211, // memcached server port, 11211 by default 'my_app', // application namespace From 639f1e8b3e95defa481c9710af2e55f4a32af330 Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 27 Jan 2024 10:41:04 +0200 Subject: [PATCH 5/6] allow mixed key data types --- src/Memory.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Memory.php b/src/Memory.php index 83817be..3c95087 100644 --- a/src/Memory.php +++ b/src/Memory.php @@ -19,7 +19,7 @@ class Memory { $this->_timeout = $timeout; } - public function get(string $key) : mixed + public function get(mixed $key) : mixed { $key = $this->_setKey( [ @@ -31,7 +31,7 @@ class Memory { return $this->_memcached->get($key); } - public function set(string $key, mixed $value = null, int $timeout = null) : bool + public function set(mixed $key, mixed $value = null, int $timeout = null) : bool { $key = $this->_setKey( [ @@ -43,7 +43,7 @@ class Memory { return $this->_memcached->set($key, $value, ($timeout ? $timeout : $this->_timeout)); } - public function delete(string $key) : bool + public function delete(mixed $key) : bool { $key = $this->_setKey( [ @@ -55,7 +55,7 @@ class Memory { return $this->_memcached->delete($key); } - public function getByValueCallback(string $key, mixed $value = null, int $timeout = null) : mixed + public function getByValueCallback(mixed $key, mixed $value = null, int $timeout = null) : mixed { $key = $this->_setKey( [ From 3e9169066ac4fa31e3227845a8d6b0a6ba6b86db Mon Sep 17 00:00:00 2001 From: ghost Date: Sat, 3 Feb 2024 01:00:45 +0200 Subject: [PATCH 6/6] fix flush delay --- src/Memory.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Memory.php b/src/Memory.php index 3c95087..3bc6858 100644 --- a/src/Memory.php +++ b/src/Memory.php @@ -117,9 +117,11 @@ class Memory { } } - public function flush(int $delay = 60) : bool + public function flush(?int $delay = 0) : bool { - return $this->_memcached->flush(); + return $this->_memcached->flush( + $delay + ); } private function _setKey(mixed $key) : string