We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

cache not expirable: lifetime

How I can set a cache file without expiration?

'lifetime' => -1

Is zero for never expire?? or -1??



145.0k
Accepted
answer

0, remember to set it both for frontend and backend.

@Wojciech should this work with modelsCache as well? I've tested but no success. Here is old topic of mine with example: https://forum.phalcon.io/discussion/12685/cachefrontenddata-lifetime-options-being-ignored

I debug with xdebug and not work!.

tested with File backend and None Frontend:

https://github.com/phalcon/cphalcon/blob/master/phalcon/cache/backend/file.zep#L140

if !lifetime {
                let lastLifetime = this->_lastLifetime;
                if !lastLifetime {
                    let ttl = (int) frontend->getLifeTime();
                } else {
                    let ttl = (int) lastLifetime;
                }
            } else {
                let ttl = (int) lifetime;
            }

            clearstatcache(true, cacheFile);
            let modifiedTime = (int) filemtime(cacheFile);

            /**
             * Check if the file has expired
             * The content is only retrieved if the content has not expired
             */
if modifiedTime + ttl > time() {


9.7k

The lifetime is used when files are retrieved. The oldest modified time is 0. The maximum time is either a 32 bit integer, something like year 2032, or a 64 bit integer. In a 64 bit system, you can set the lifetime to mktime(0, 0, 0, 0, 0, 5000) or to time()*10.