Fixed Cache without lifetime not working

TnT

Active member
Affected version
2.3.0 Beta 1
While testing 2.3.0 Beta 1 i figured out, caching without liefetime like this:

PHP:
\XF::app()->cache()->save('test', 'works');

returns true, but

PHP:
\XF::app()->cache()->fetch('test');

returns false. Setting lifetime explicit to 0 also returns false.
Only Providing a livetime returns the expected cache result.

Only this works:

PHP:
\XF::app()->cache()->save('test', 'works', 10);
\XF::app()->cache()->fetch('test');

In my use case i store an item which is frequently fetched independently in cache and update this via cron.
 
This is a consequence of PSR-6 being something of a garbage interface design around expiry handling, and then how XF bolts onto it

You need to pass null to expiresAfter, but the save()'s lifeTime argument is an int.

\Doctrine\Common\Cache\CacheProvider::getCacheItemForSave needs patching so it passes null to expiresAfter instead of 0.
 
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.0 Beta 2).

Change log:
Fix indefinite item expiry in Doctrine cache shim
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom