terrylinooo / simple-cache

PSR-16 simple cache drivers for PHP.
MIT License
87 stars 2 forks source link

apcu part is not handling multiple websites well #10

Closed f1-outsourcing closed 1 year ago

f1-outsourcing commented 3 years ago

apcu part is not handling multiple websites well. See https://github.com/terrylinooo/cache-master/issues/7

This is how the 'w3 total cache' plugin uses apcu. I guess if you incorporate something like the website name with using the cache, this should be fixed.

w3tc_915778564__34_pgcache_dadcd63b66f42d4e8e6246980ab7fc70_gzip | 8 | 1104 | 2021/08/24 13:40:27 | 2021/08/24 13:38:02 | 2021/08/24 13:38:02 | 86400 seconds | [Delete Now]
w3tc_915778564__33_pgcache_8ff652f57f5ec5b6f56a9e382cb01575_gzip | 4 | 5200 | 2021/08/20 07:51:43 | 2021/08/19 20:17:44 | 2021/08/19 20:17:44 | 86400 seconds | [Delete Now]
w3tc_915778564__1_pgcache_9349156837b1d706e1884c4c6be7f5cc | 4 | 15952 | 2021/08/24 12:45:08 | 2021/08/24 04:01:11 | 2021/08/24 04:01:11 | 86400 seconds | [Delete Now]
w3tc_915778564__33_pgcache_eec34b1b18b401377174ae2548bff425_gzip | 3 | 1104 | 2021/08/20 07:51:33 | 2021/08/19 20:17:46 | 2021/08/19 20:17:46 | 86400 seconds | [Delete Now]
w3tc_915778564__34_pgcache_a2452f70a22449f2d8aceab1723c973c_gzip | 2 | 5200 | 2021/08/24 13:39:42 | 2021/08/24 13:38:10 | 2021/08/24 13:38:10 | 86400 seconds | [Delete Now]
w3tc_915778564__34_pgcache_2ef4ed86b1ce00114efdd0cfdf8301b6_gzip | 2 | 4688 | 2021/08/24 13:54:06 | 2021/08/24 13:37:59 | 2021/08/24 13:37:59 | 86400 seconds | [Delete Now]
w3tc_915778564__33_pgcache_7c73ba90c2b3eeeed89d664d89adbff4_gzip | 2 | 6224 | 2021/08/23 19:45:32 | 2021/08/23 16:56:14 | 2021/08/23 16:56:14 | 86400 seconds | [Delete Now]
w3tc_915778564__33_pgcache_4f8e342babbf61c28004677c44c73824_gzip | 2 | 568 | 2021/08/20 07:21:03 | 2021/08/19 19:15:48 | 2021/08/19 19:15:48 | 86400 seconds | [Delete Now]
f1-outsourcing commented 3 years ago

Yes something like this fixes it, not sure if it is necessary to crc32() the server name.

protected function getAll(): array
{
    $list = [];

    $prefix = 'sc_'.$_SERVER['SERVER_NAME'].'_';

    foreach (new APCUIterator('/^'.$prefix.'/') as $item) {
        $key = str_replace($prefix, '', $item['key']);
        $value = unserialize($item['value']);

        $list[$key] = $value;
    }

    return $list;
}

/**
 * Get the key name of a cache.
 *
 * @param string $key The key of a cache.
 *
 * @return string
 */
private function getKeyName(string $key): string
{
    $prefix = 'sc_'.$_SERVER['SERVER_NAME'].'_';

    return $prefix . $key;
}
f1-outsourcing commented 3 years ago

Maybe fix this?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 2 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 since being marked as stale.