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

Fix for expiration intervals longer than 30 days #436

Merged
merged 3 commits into from Feb 27, 2014

Conversation

leonid-shevtsov
Copy link
Contributor

I have found out (the hard way) that memcached silently doesn't store values with expiration over 30 days. (previously: #55 #251 #357)

Upon studying the code, I've decided that the best way to handle this is to transparently rewrite long expiration intervals into expiration timestamps, as the Memcached API asks.

Tests are provided, I've also tested the code integrated into my own environment, a debug message is logged when the translation happens, and nothing changes in the documented API.

What will change in existing apps is

  • apps that unknowingly use bad expiration intervals (such as 1 year) will suddenly start caching as intended
  • apps that knowingly exploit the "bug" will get wrong expiration timestamps in the far future.

I think compliance to APIs is worth breaking the latter. An safer alternative could be to provide both :expires_in and :expires_on options, and throw exceptions on invalid timestamps and intervals, but Rails, for one, doesn't even have :expires_on.

@mperham
Copy link
Collaborator

mperham commented Feb 26, 2014

We already have a test_server file, would you move your tests into it?

@mperham
Copy link
Collaborator

mperham commented Feb 26, 2014

And update the changelog please

@leonid-shevtsov
Copy link
Contributor Author

Done!

mperham added a commit that referenced this pull request Feb 27, 2014
Fix for expiration intervals longer than 30 days
@mperham mperham merged commit dfd1bfb into petergoldstein:master Feb 27, 2014
@eirc
Copy link

eirc commented Jul 10, 2014

THANK YOU FOR THIS!! (also found out about it the hard way...)

@annaswims
Copy link

For anyone else that stumbles across this problem, Rails adds 5 minutes to the ttl for reasons that I don't understand. So, :expires_on => 30.days ends up being being greater than 30 days rails/rails@13d8777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants