From 02234783c6f0fd9b15faf7a17d3bb8b1d39da557 Mon Sep 17 00:00:00 2001 From: v12mike Date: Sun, 15 Jul 2018 21:50:18 +0100 Subject: [PATCH 1/7] [ticket/15726] Implement selective purge in APCu cache driver The current APCu cache driver implements a global clearing of the APCu when the phpBB cache is purged. This is inappropriate if there are other phpBB boards, or other php applications sharing the APCu cache. This patch changes the behviour so that only cache entries matching the key_prefix of this board are cleared by a phpBB cache purge. The APCu unit test script has been updated to test this behaviour. It has also been updated so that the test case can be run individually previously it relied on initialisations made in other test scripts. PHPBB3-15726 --- phpBB/phpbb/cache/driver/apcu.php | 6 +++++- tests/cache/apcu_driver_test.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) mode change 100644 => 100755 phpBB/phpbb/cache/driver/apcu.php mode change 100644 => 100755 tests/cache/apcu_driver_test.php diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php old mode 100644 new mode 100755 index 40192e4026..6a65e7155a --- a/phpBB/phpbb/cache/driver/apcu.php +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -25,7 +25,11 @@ class apcu extends \phpbb\cache\driver\memory */ function purge() { - apcu_clear_cache(); + /* use an iterator to selectively clear our cache entries without + disturbing any other cache users + (e.g. other phpBB boards hosted on this server) */ + apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#')); + parent::purge(); } diff --git a/tests/cache/apcu_driver_test.php b/tests/cache/apcu_driver_test.php old mode 100644 new mode 100755 index 9de1d82a15..2002fb66d8 --- a/tests/cache/apcu_driver_test.php +++ b/tests/cache/apcu_driver_test.php @@ -49,10 +49,27 @@ class phpbb_cache_apcu_driver_test extends phpbb_cache_common_test_case protected function setUp() { + global $phpbb_container, $phpbb_root_path; + parent::setUp(); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/'); + $this->driver = new \phpbb\cache\driver\apcu; $this->driver->purge(); } + + public function test_purge() + { + /* add a cache entry which does not match our key */ + $foreign_key = 'test_' . $this->driver->key_prefix . 'test'; + $this->assertSame(true, apcu_store($foreign_key, 0, 600)); + $this->assertSame(true, apcu_exists($foreign_key)); + + parent::test_purge(); + + $this->assertSame(true, apcu_exists($foreign_key)); + } } From 63a3033f15428b1af9a121708eb4a2bd4bef43c0 Mon Sep 17 00:00:00 2001 From: v12mike Date: Mon, 16 Jul 2018 06:36:38 +0200 Subject: [PATCH 2/7] [ticket/15726] Implement selective purge in APCu cache driver Fix whitespace PHPBB3-15726 --- phpBB/phpbb/cache/driver/apcu.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php index 6a65e7155a..754fb1fce2 100755 --- a/phpBB/phpbb/cache/driver/apcu.php +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -25,11 +25,10 @@ class apcu extends \phpbb\cache\driver\memory */ function purge() { - /* use an iterator to selectively clear our cache entries without - disturbing any other cache users - (e.g. other phpBB boards hosted on this server) */ - apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#')); - + /* use an iterator to selectively clear our cache entries without + disturbing any other cache users + (e.g. other phpBB boards hosted on this server) */ + apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#')); parent::purge(); } From 7d4d9770cfc38d613c3cf2b8495d2f8e63623ebd Mon Sep 17 00:00:00 2001 From: v12mike Date: Mon, 16 Jul 2018 07:26:14 +0100 Subject: [PATCH 3/7] [ticket/15726] Implement selective purge in APCu cache driver fix file permissions PHPBB3-15726 --- phpBB/phpbb/cache/driver/apcu.php | 0 tests/cache/apcu_driver_test.php | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 phpBB/phpbb/cache/driver/apcu.php mode change 100755 => 100644 tests/cache/apcu_driver_test.php diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php old mode 100755 new mode 100644 diff --git a/tests/cache/apcu_driver_test.php b/tests/cache/apcu_driver_test.php old mode 100755 new mode 100644 From bf9af922208ad93c2afbe4fa9462f8914c8d4363 Mon Sep 17 00:00:00 2001 From: v12mike Date: Wed, 25 Jul 2018 19:36:25 +0100 Subject: [PATCH 4/7] [ticket/15726] Implement selective purge in APCu cache driver Correcting code formatting and whitespace PHPBB3-15726 --- phpBB/phpbb/cache/driver/apcu.php | 7 ++++--- tests/cache/apcu_driver_test.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php index 754fb1fce2..e40d5a376c 100644 --- a/phpBB/phpbb/cache/driver/apcu.php +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -25,9 +25,10 @@ class apcu extends \phpbb\cache\driver\memory */ function purge() { - /* use an iterator to selectively clear our cache entries without - disturbing any other cache users - (e.g. other phpBB boards hosted on this server) */ + /* + Use an iterator to selectively clear our cache entries without disturbing + any other cache users (e.g. other phpBB boards hosted on this server) + */ apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#')); parent::purge(); diff --git a/tests/cache/apcu_driver_test.php b/tests/cache/apcu_driver_test.php index 2002fb66d8..57f640c313 100644 --- a/tests/cache/apcu_driver_test.php +++ b/tests/cache/apcu_driver_test.php @@ -61,7 +61,7 @@ class phpbb_cache_apcu_driver_test extends phpbb_cache_common_test_case $this->driver->purge(); } - public function test_purge() + public function test_purge() { /* add a cache entry which does not match our key */ $foreign_key = 'test_' . $this->driver->key_prefix . 'test'; From 7f1f64b1dcebb28ab575e1905676471b473d08ed Mon Sep 17 00:00:00 2001 From: v12mike Date: Thu, 26 Jul 2018 06:09:02 +0100 Subject: [PATCH 5/7] [ticket/15726] Implement selective purge in APCu cache driver Fix whitespace PHPBB3-15726 --- phpBB/phpbb/cache/driver/apcu.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php index e40d5a376c..3a63a97e4e 100644 --- a/phpBB/phpbb/cache/driver/apcu.php +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -25,9 +25,9 @@ class apcu extends \phpbb\cache\driver\memory */ function purge() { - /* - Use an iterator to selectively clear our cache entries without disturbing - any other cache users (e.g. other phpBB boards hosted on this server) + /* + * Use an iterator to selectively clear our cache entries without disturbing + * any other cache users (e.g. other phpBB boards hosted on this server) */ apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#')); From 33268e5a72b3858c09d97bb696a21911ec139815 Mon Sep 17 00:00:00 2001 From: v12mike Date: Thu, 26 Jul 2018 17:24:42 +0200 Subject: [PATCH 6/7] [ticket/15726] Implement selective purge in APCu cache driver Edit comment PHPBB3-15726 --- phpBB/phpbb/cache/driver/apcu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php index 3a63a97e4e..4b06fdb002 100644 --- a/phpBB/phpbb/cache/driver/apcu.php +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -26,7 +26,7 @@ class apcu extends \phpbb\cache\driver\memory function purge() { /* - * Use an iterator to selectively clear our cache entries without disturbing + * Use an iterator to selectively delete our cache entries without disturbing * any other cache users (e.g. other phpBB boards hosted on this server) */ apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#')); From 5edb33036654fad4df63507f00934b0d078e2756 Mon Sep 17 00:00:00 2001 From: v12mike Date: Sun, 29 Jul 2018 09:15:12 +0100 Subject: [PATCH 7/7] [ticket/15726] Implement selective purge in APCu fix indentation of comment PHPBB3-15726 --- phpBB/phpbb/cache/driver/apcu.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php index 4b06fdb002..c96cf0de57 100644 --- a/phpBB/phpbb/cache/driver/apcu.php +++ b/phpBB/phpbb/cache/driver/apcu.php @@ -25,10 +25,10 @@ class apcu extends \phpbb\cache\driver\memory */ function purge() { - /* - * Use an iterator to selectively delete our cache entries without disturbing - * any other cache users (e.g. other phpBB boards hosted on this server) - */ + /* + * Use an iterator to selectively delete our cache entries without disturbing + * any other cache users (e.g. other phpBB boards hosted on this server) + */ apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#')); parent::purge();