Make CacheHandler::getCacheName() less expensive
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 2 Mar 2022 15:24:59 +0000 (16:24 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 2 Mar 2022 16:06:54 +0000 (17:06 +0100)
The old implementation generated cache filenames that are a little cleaner to
the human eye, but the generation was needlessly expensive, even calling the
UTF-8-safe StringUtil::firstCharToUpperCase() on an ASCII value.

It will need to be checked if the changing cache name will cause issues during
the upgrade to 5.5, as it will implicitly result in a cache clear.

wcfsetup/install/files/lib/system/cache/CacheHandler.class.php

index 7a4fbcaec8736407a15b7b3b7eff8ca09fe39738..6775704b8f2098e6cc5940133e0f5476758b6608 100644 (file)
@@ -6,7 +6,6 @@ use wcf\system\cache\builder\ICacheBuilder;
 use wcf\system\cache\source\DiskCacheSource;
 use wcf\system\exception\SystemException;
 use wcf\system\SingletonFactory;
-use wcf\util\StringUtil;
 
 /**
  * Manages transparent cache access.
@@ -118,14 +117,16 @@ class CacheHandler extends SingletonFactory
      */
     protected function getCacheName(ICacheBuilder $cacheBuilder, array $parameters = [])
     {
-        $className = \explode('\\', \get_class($cacheBuilder));
-        $application = \array_shift($className);
-        $cacheName = \str_replace('CacheBuilder', '', \array_pop($className));
+        $cacheName = \str_replace(
+            ['\\', 'system_cache_builder_'],
+            ['_', ''],
+            \get_class($cacheBuilder)
+        );
         if (!empty($parameters)) {
             $cacheName .= '-' . $this->getCacheIndex($parameters);
         }
 
-        return $application . '_' . StringUtil::firstCharToUpperCase($cacheName);
+        return $cacheName;
     }
 
     /**