PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.36k stars 452 forks source link

Memcached driver compress_data cache miss #889

Closed iftaras closed 1 year ago

iftaras commented 1 year ago

What type of issue is this?

Incorrect/unexpected/unexplainable behavior

Operating system + version

Ubuntu 20.04 5.10.16.3-microsoft-standard-WSL2

PHP version

8.1.12

Connector/Database version (if applicable)

Memcached 1.6.18 + PECL Extension 3.2.0

Phpfastcache version

9.1.2 ✅

Describe the issue you're facing

During configuration of the Memcached instance if we specify the compress_data option either be true or false we always hit a cache miss even though the data exists.

Expected behavior

Since the data exists on the Memcached server we should get true when querying isHit().

Code sample (optional)

Instance configuration:

$memcached = CacheManager::getInstance('Memcached', new MemcachedConfig([
        'host' => $_ENV['ME_HOST'],
        'port' => intval($_ENV['MEM_PORT']),
        'saslUser' => $_ENV['MEM_USER'] ?? '',
        'saslPassword' => $_ENV['MEM_PASS'] ?? '',
        'optPrefix' => 'testing_',
        'defaultTtl' => 90,
        'compress_data' => true,
        'preventCacheSlams' => true,
        'cacheSlamsTimeout' => 3
]));

Example:

$cacheItem = $memcached->getItem('get_exampleData');

if (!$cacheItem->isHit()) {
    echo 'CACHE MISS';
    $data = 'get_the_data_from_the_db';
    $cacheItem->set($data);
    $cacheItem->setTags(['data', 'homepage', 'summary']);
    $memcached->save($cacheItem);
} else {
    echo 'CACHE HIT!!!!';
    $data = $cacheItem->get();
}

In the example above no matter how many passes we do, we will always get CACHE MISS. If we remove the compress_data option from the configuration everything returns to normal.

Suggestion to fix the issue (optional)

No response

References (optional)

No response

Do you have anything more you want to share? (optional)

No response

Have you searched in our Wiki before posting ?

github-actions[bot] commented 1 year ago

Hello curious contributor ! Since it seems to be your first contribution, make sure that you've been:

Geolim4 commented 1 year ago

Hello,

I'm not sure if you have a try/catch somewhere in your code, but this code is definitely triggering me an error:

image

[Begin Test: Memcached]
[PHPFASTCACHE: CORE v9.1.2#c2dfc471 | API v4.2.0]
[PHP v8.0.27 with: bcmath, calendar, Core, ctype, curl, date, dom, fileinfo, filter, gettext, grpc, hash, iconv, json, libxml, mbstring, memcached, mongodb, mysqlnd, openssl, pcre, PDO, pdo_sqlite, Phar, readline, Reflection, session, SimpleXML, SPL, standard, tokenizer, xml, xmlreader, xmlwriter, zip, zlib]
---
[FAIL] Uncaught exception "Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException" in "~/lib/Phpfastcache/Config/ConfigurationOption.php" line 64 with message: "Unknown configuration option name "compress_data" for the config class "Phpfastcache\Drivers\Memcached\Config". Allowed configurations options are "servers", "host", "port", "saslUser", "saslPassword", "optPrefix", "itemDetailedDate", "autoTmpFallback", "defaultTtl", "defaultKeyHashFunction", "defaultFileNameHashFunction", "path", "preventCacheSlams", "cacheSlamsTimeout", "useStaticItemCaching", "superGlobalAccessor""
Test results:  1 assertion failed, 0 assertions skipped and 0 assertions passed out of a total of 1 assertion.
Test duration: 0.072s

Also make sure you phpfastcache version is up to date, since the option compress_data has been removed a long time ago.

iftaras commented 1 year ago

My apologies, you are correct. I had a fallback instance which resulted in a cache miss. The compress_data option though is still referenced for Memcache(d) in the Global configuration options wiki page.

Geolim4 commented 1 year ago

Ohh right, I fixed the Wiki, thanks !