Describe the bug
As a module developer i wanted to use variable based Cache (instead of the page wide Smarty cache) by using Cache::getInstance(). Unfortunately, either the value is never set or the check if there is a cached value fails, it always returns false.
To Reproduce
$cache = Cache::getInstance();
$cache->set($key, $data, 0);
if($cache->exists($key))
echo $cache->get($key);
exists() always returns false.Screenshots
If applicable, add screenshots or screenrecords to help explain your problem.
Additional information
There is a bugrequest PSCSX-7149 in "the forge" which seems relevant. I cant use the Smarty caching as a workaround since it doesnt feature a TTL yet. Maybe PR 8855 fixes this problem?
PrestaShop version: 1.7.5.0 based on Symfony 3.4.19 from a docker container using prestashop/prestashop:1.7 against MariaDB in a docker container using mariadb/server:10.3
PHP version: 5.6.39
Hi @x29a,
Could you please provide me with your custom module to test it.
This is a public space.
You can provide me the module by email.
My address mail: khouloud.[email protected]
Let's be safe!
Thanks!
@khouloudbelguith thanks for the quick response, i created a mcve i attached here.
When loading the module, it should show in displayHome or displayRightColumn:
TestCache Template!
Message from Cache system: cache updated with: 'yo this is loaded from cache' !
After a page reload, i would expect:
TestCache Template!
Message from Cache system: cache loaded: 'yo this is loaded from cache' !
yet i always get the first message.
I dont get any PHP errors.
Updated the sample module to use Cache::store() and related static functions, same result :/
Hi @x29a,
Thanks for your feedback.
After installing your module, I checked the positions of this module & it is OK.

In the FO, also, I have this text displayed
TestCache Template!
Message from Cache system: cache updated with: 'yo this is loaded from cache' !

Thanks to check & feedback.
Thank you for trying the module.
Installing, loading and positioning of the module works great. What does not work is using the Cache class as described in my original post. When looking at my second example modules code, there are two different approaches (moduleDisplay2() and moduleDisplay2()) tried and both dont work.
The result is, when you refresh your shops site, the same text will be displayed meaning the value is freshly fetched from source and not from cache. If caching worked, it would show:
TestCache Template!
Message from Cache system: cache loaded: 'yo this is loaded from cache' !
Did you have a look at the modules code or the linked stackoverflow post to see if in general the class is used correctly and should work like this? As i understand this is a seperate mechanism from Smarty's caching mechanism. The goal is fetch data from an external site only e.g. each hour and serve intermediate requests from a local cache.
@x29a, thanks for the clarifications.
Yes, whan I reload the page,
TestCache Template!
Message from Cache system: cache loaded: 'yo this is loaded from cache' !
is not displayed.
ping @eternoendless, @PrestaShop/prestashop-core-developers what do you think?
Thanks!
Might this be related with the removal of CacheFs.php implementation? In 1.6.x it was still present, in 1.7.x it is not, as implemented by this pull request. I found it in this changelog.
What was the reason behind the decision? Is there a substitute?
As mentioned in the linked PR, filebased caching was probably considered less efficient and therefor removed. I still think its a good fallback.
I tried using the 1.7 caching via memcache (which is the default when one enables caching in the shop performance settings), but the extension is not present in the docker image (i verified via this code).
So i think the problem is twofold:
Hello @x29a indeed I agree with you there is something missing:
Cache::getInstance should return an ArrayCache (which only stores values for one process), or maybe even a "NullCache" which would always return false when fetching a valueWatch out, don't mix up Memcache and Memcached which are different. More because Memcache is very old and don't work with latest php version.
Thank you both for your answers!
@PierreRambaud i was only referring memcache (without the D) because it currently is selected-by-default option. Maybe your comment is an indication that it should be removed along the way.
@jolelievre This just introduced another aspect, so i see a multistep approach
memcache (without the D) support as stated by @PierreRambaud (or at least add check for proper working PHP version)Cache class altogether (as you suggested, you know the reasons best)Well, this escalated quickly. How to procede from here?
After a very long time. I investigate on this issue.
The first method moduleDisplay` is using the cache which is settled here:

The seconde one moduleDisplay2 is using a local cache, Cache::store and Cache::retrieve used a $local variable.
And everything is working well :thinking:
I'm against using FS as fallback, some websites are not running under system allowing files to be written, it uses external cache server.
This has been a while and the specific problem has been worked around, i accept your decisions and close this issue. Thanks for looking into it!