Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileCache not expiring #11759

Closed
stratoss opened this issue May 7, 2016 · 3 comments
Closed

FileCache not expiring #11759

stratoss opened this issue May 7, 2016 · 3 comments
Assignees
Labels
bug A bug report stale Stale issue - automatically closed status: medium Medium

Comments

@stratoss
Copy link

stratoss commented May 7, 2016

Here is the sample code:

$di->setShared('cache', function() {
    //Cache data for one hour by default
    $frontCache = new \Phalcon\Cache\Frontend\Data(array(
        'lifetime' => 3600
    ));

    //File cache settings
    $cache = new \Phalcon\Cache\Backend\File($frontCache, array(
        'cacheDir' => __DIR__ . '/cache/'
    ));

    return $cache;
});

then

$resetAfter = $rate['saved'] + $seconds - time();
$cache->save($cacheName, $rate, (float)$resetAfter);

After a while $resetAfter becomes negative, and $cache->exists($cacheName) still returns the value...

edit: not touched the file for > 3600 seconds, and the file is still there. Looks like a bug for me.

@stratoss stratoss changed the title FileCache never expires FileCache not expiring May 7, 2016
@stratoss
Copy link
Author

stratoss commented May 8, 2016

Hmm I've checked out the cache/backend/file.zep and realized that filemtime() returns the modified time on unix platforms, also I believed that passing lifetime while setting the cache is working as it does using memcached or redis for example, but the File implementation is totally different.

I think that setting a lifetime of 5 seconds for example while saving should invalidate (delete) that cache if accessed after these 5 seconds, otherwise the lifetime attribute is useless, so I must know the expiration time and pass the same value over and over again to exists, get and save which doesn't sounds right to me.

Do you think that instead of saving the raw content passed to save() saving an array like

['created' => time(), 'lifetime' => $lifetime, 'content' => $content]

is a good idea? It will solve the problem described above and the File cache will start behaving just like it does using memcached or redis? I could do a PR with the changes if you agree.

If you didn't, I believe the documentation should explicitly explain that lifetime passed to save must be passed to check and get as well in order to work.

@sergeyklay
Copy link
Contributor

@stratoss Could you please create PR for 2.0.x branch? Note, test coverage of this changes is mandatory.

stratoss pushed a commit to stratoss/cphalcon that referenced this issue May 9, 2016
@sergeyklay sergeyklay self-assigned this Jun 28, 2016
stratoss pushed a commit to stratoss/cphalcon that referenced this issue Jul 11, 2016
@stale
Copy link

stale bot commented Apr 17, 2018

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

@stale stale bot added the stale Stale issue - automatically closed label Apr 17, 2018
CameronHall pushed a commit to CameronHall/cphalcon that referenced this issue Nov 27, 2018
CameronHall pushed a commit to CameronHall/cphalcon that referenced this issue Nov 28, 2018
niden pushed a commit that referenced this issue Nov 29, 2018
@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report stale Stale issue - automatically closed status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants