Skip to content

Commit e25f203

Browse files
committed
fix: improve key cache performance
1 parent e0066c6 commit e25f203

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Cache.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Cache extends SingletonAbstract
88
{
99
protected static $cache;
10-
protected static $prefix = 'cache_';
10+
protected static $ext = 'cache';
1111
protected static $DS = DIRECTORY_SEPARATOR;
1212

1313
protected $tempdir;
@@ -173,7 +173,13 @@ public function deleteRegex($pattern = '*')
173173
*/
174174
protected function key($key)
175175
{
176-
return self::$prefix . md5($key);
176+
$filename = $key . '.' . self::$ext;
177+
$special_chars = array('?', '[', ']', '/', '\\', '=', '<', '>', ':', ';', ',', "'", '"', '&', '$', '#', '*', '(', ')', '|', '~', '`', '!', '{', '}');
178+
$filename = str_replace($special_chars, '', $filename);
179+
$filename = preg_replace('/[\s-]+/', '-', $filename);
180+
$filename = trim($filename, '.-_');
181+
182+
return $filename;
177183
}
178184

179185
/**

src/Modules/Wordpress.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static function getPluginHeaders($file)
163163
public static function getChecksums($version, $locale = 'en_US')
164164
{
165165
$cache = Cache::getInstance();
166-
$key = 'wordpress_' . $version . '-' . $locale;
166+
$key = 'wordpress_' . $locale . '-' . $version;
167167
$checksums = $cache->get($key);
168168

169169
if (is_null($checksums)) {
@@ -203,7 +203,7 @@ public static function getPluginsChecksums($plugins = array())
203203
$cache = Cache::getInstance();
204204
$pluginsChecksums = array();
205205
foreach ($plugins as $plugin) {
206-
$key = 'wordpress_' . $plugin['domain'] . '-' . $plugin['version'];
206+
$key = 'wordpress-plugin_' . $plugin['domain'] . '-' . $plugin['version'];
207207
$checksums = $cache->get($key);
208208

209209
if (!is_null($checksums)) {

0 commit comments

Comments
 (0)