From cd9cc01b7739535cc9246103f90ae2d02d8ea217 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 10 Jul 2024 12:42:46 +0200 Subject: [PATCH 1/5] fix: set default TTL for APCu cache as per docs Signed-off-by: Robin Appelman --- lib/private/Memcache/APCu.php | 6 ++++++ lib/public/ICache.php | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lib/private/Memcache/APCu.php b/lib/private/Memcache/APCu.php index 7f6a73354eed1..9eb2ee0b2bf14 100644 --- a/lib/private/Memcache/APCu.php +++ b/lib/private/Memcache/APCu.php @@ -25,6 +25,9 @@ public function get($key) { } public function set($key, $value, $ttl = 0) { + if ($ttl === 0) { + $ttl = self::DEFAULT_TTL; + } return apcu_store($this->getPrefix() . $key, $value, $ttl); } @@ -56,6 +59,9 @@ public function clear($prefix = '') { * @return bool */ public function add($key, $value, $ttl = 0) { + if ($ttl === 0) { + $ttl = self::DEFAULT_TTL; + } return apcu_add($this->getPrefix() . $key, $value, $ttl); } diff --git a/lib/public/ICache.php b/lib/public/ICache.php index ba6016c8d283b..5e755d81e1448 100644 --- a/lib/public/ICache.php +++ b/lib/public/ICache.php @@ -15,6 +15,11 @@ * @since 6.0.0 */ interface ICache { + /** + * @since 30.0.0 + */ + public const DEFAULT_TTL = 24 * 60 * 60; + /** * Get a value from the user cache * @param string $key From 4691d197707e84173800c5c225d5395fee53db17 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 10 Jul 2024 22:23:37 +0200 Subject: [PATCH 2/5] docs: clearify IMemcache::inc and dec behavior Signed-off-by: Robin Appelman --- lib/public/IMemcache.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/public/IMemcache.php b/lib/public/IMemcache.php index fbc2719c25de9..6e63884ff4513 100644 --- a/lib/public/IMemcache.php +++ b/lib/public/IMemcache.php @@ -30,6 +30,9 @@ public function add($key, $value, $ttl = 0); /** * Increase a stored number * + * If no value is stored with the key, it will behave as if a 0 was stored. + * If a non-numeric value is stored, the operation will fail and `false` is returned. + * * @param string $key * @param int $step * @return int | bool @@ -40,6 +43,9 @@ public function inc($key, $step = 1); /** * Decrease a stored number * + * If no value is stored with the key, the operation will fail and `false` is returned. + * If a non-numeric value is stored, the operation will fail and `false` is returned. + * * @param string $key * @param int $step * @return int | bool From b19652a2add61d652e0e8385c44de942eee611a1 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 10 Jul 2024 22:32:47 +0200 Subject: [PATCH 3/5] chore: cleanup acpu inc and dec Signed-off-by: Robin Appelman --- lib/private/Memcache/APCu.php | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/lib/private/Memcache/APCu.php b/lib/private/Memcache/APCu.php index 9eb2ee0b2bf14..024462d227b9e 100644 --- a/lib/private/Memcache/APCu.php +++ b/lib/private/Memcache/APCu.php @@ -73,22 +73,8 @@ public function add($key, $value, $ttl = 0) { * @return int | bool */ public function inc($key, $step = 1) { - $this->add($key, 0); - /** - * TODO - hack around a PHP 7 specific issue in APCu - * - * on PHP 7 the apcu_inc method on a non-existing object will increment - * "0" and result in "1" as value - therefore we check for existence - * first - * - * on PHP 5.6 this is not the case - * - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 - * for details - */ - return apcu_exists($this->getPrefix() . $key) - ? apcu_inc($this->getPrefix() . $key, $step) - : false; + $success = null; + return apcu_inc($this->getPrefix() . $key, $step, $success, self::DEFAULT_TTL); } /** @@ -99,18 +85,6 @@ public function inc($key, $step = 1) { * @return int | bool */ public function dec($key, $step = 1) { - /** - * TODO - hack around a PHP 7 specific issue in APCu - * - * on PHP 7 the apcu_dec method on a non-existing object will decrement - * "0" and result in "-1" as value - therefore we check for existence - * first - * - * on PHP 5.6 this is not the case - * - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 - * for details - */ return apcu_exists($this->getPrefix() . $key) ? apcu_dec($this->getPrefix() . $key, $step) : false; From cae0a8218da63fad6b6808b0051f4db1f196a79a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 10 Jul 2024 23:00:05 +0200 Subject: [PATCH 4/5] chore: remove Redis::DEFAULT_TTL constant now that it's defined in the interface Signed-off-by: Robin Appelman --- lib/private/Memcache/Redis.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php index cbafadc3b1b90..87dc86ab10d30 100644 --- a/lib/private/Memcache/Redis.php +++ b/lib/private/Memcache/Redis.php @@ -29,7 +29,6 @@ class Redis extends Cache implements IMemcacheTTL { ], ]; - private const DEFAULT_TTL = 24 * 60 * 60; // 1 day private const MAX_TTL = 30 * 24 * 60 * 60; // 1 month /** From 5490b12febf6ac2b93d320ed5521b272faa6f73a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 7 Aug 2024 19:35:50 +0200 Subject: [PATCH 5/5] chore: add psalm false positive to psalm.xml Signed-off-by: Robin Appelman --- psalm.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/psalm.xml b/psalm.xml index 05ea0ef20bcb3..dece0c3eb8886 100644 --- a/psalm.xml +++ b/psalm.xml @@ -151,5 +151,12 @@ + + + + + + +