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

Comments

Projects
None yet
2 participants
@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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

sergeyklay commented May 9, 2016

@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

This comment has been minimized.

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 label Apr 17, 2018

@sergeyklay sergeyklay closed this Apr 17, 2018

CameronHall added a commit to CameronHall/cphalcon that referenced this issue Nov 27, 2018

@CameronHall CameronHall referenced this issue Nov 27, 2018

Merged

Fixes #11759 and deletes expired keys #13621

3 of 3 tasks complete

CameronHall added a commit to CameronHall/cphalcon that referenced this issue Nov 28, 2018

niden added a commit that referenced this issue Nov 29, 2018

niden added a commit to niden/cphalcon that referenced this issue Dec 4, 2018

[phalcon#13578] - Merge branch '4.0.x' into T13578-setup-phalcon-envi…
…ronment

* 4.0.x:
  Textarea output is automatically escaped
  Fixes phalcon#11759 and deletes expired keys
  Doc Add the ability to use FrontendInterface to serialize Model and ResultSet
  [NFR] Add FrontendInterface to serialize Model and Resultset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment