Lack of interest Expose Doctrine\Common\Cache\Apcu for XF Cache

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.
Adding the patch below allows using APCu without APC-BC (backwards compatibility). Some environments don't provide the backwards-compatibility package for APCu and nobody is actually using the "real" APC these days, so it doesn't make sense to make it impossible to use APCu directly.

The code could be modified to automatically detect which one is available based on apc_fetch/apcu_fetch existence.

Diff:
--- src/XF/CacheFactory.php.bak 2019-01-27 01:32:31.924677238 +0100
+++ src/XF/CacheFactory.php     2019-01-27 01:33:03.213712677 +0100
@@ -92,6 +92,16 @@
                return new Cache\ApcCache();
        }
 
+       protected function createApcuCache(array $config)
+       {
+               if (!function_exists('apcu_fetch'))
+               {
+                       throw new \LogicException("Cannot load APCu cache provider without APCu");
+               }
+
+               return new Cache\ApcuCache();
+       }
+
        protected function createFilesystemCache(array $config)
        {
                if (empty($config['directory']))

Configuration:
PHP:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Apcu';
 
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
To echo my comments from the bug report, and also to hint to others how this is already possible, please see this post:
While not a bug, it is a reasonable suggestion, but it is something you can implement yourself for now if you wish to, without changing the XF code.

The CacheFactory is capable of instantiating cache providers via a closure defined in src/config.php. So you don't need to invalidate any file hashes at all, you just add the following to the config file:
PHP:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = function()
{
    return new \Doctrine\Common\Cache\ApcuCache();
};
We'll consider changes in the future, but in the meantime the system was designed in this way specifically for the purpose of being able to configure other cache providers that we don't support out of the box if you want to.
 
Top Bottom