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

Silently doesn't work if TTL is over 30 days #251

Closed
henrik opened this issue Aug 12, 2012 · 4 comments
Closed

Silently doesn't work if TTL is over 30 days #251

henrik opened this issue Aug 12, 2012 · 4 comments

Comments

@henrik
Copy link

henrik commented Aug 12, 2012

This works:

require "dalli"
dc = Dalli::Client.new('localhost:11211')
dc.set "test", "works", 60*60*24*30
puts(dc.get("test") || "fails")

This fails:

require "dalli"
dc = Dalli::Client.new('localhost:11211')
dc.set "test", "works", 60*60*24*30 + 1
puts(dc.get("test") || "fails")

This was confusing to me and took a while to debug. I now know that memcache expiry given in seconds can't be higher than 30 days (I should probably just use 0 = never expire), but perhaps Dalli could raise an exception for expiry times over 30 days to help you catch these mistakes?

If you'd like, I'll make a pull request, but I wanted to check if you want this behavior, first.

@mperham
Copy link
Collaborator

mperham commented Aug 12, 2012

More than 30 days and memcached treats the value as a Unix timestamp, so Time.now.to_i + 300 will get you a 5 min TTL.

@mperham mperham closed this as completed Aug 12, 2012
@henrik
Copy link
Author

henrik commented Aug 12, 2012

Thanks. So I suppose 60*60*24*30 + 1 is interpreted as though it were Time.at(60*60*24*30 + 1) then, i.e. 1970-01-31 00:00:01 UTC.

Dalli could still raise or log a warning when you set an expiry that's interpreted as being in the past, but I can see how you wouldn't want to go there.

Do you think you might accept a pull request that mentions this in the Dalli README, then?

@mperham
Copy link
Collaborator

mperham commented Aug 12, 2012

I would accept a patch for the #set rdoc. It's not something that belongs
in the readme.

On Sun, Aug 12, 2012 at 9:14 AM, Henrik Nyh notifications@github.comwrote:

Thanks. So I suppose 60_60_24_30 + 1 is interpreted as though it were Time.at(60_60_24_30

    1. then, i.e. 1970-01-31 00:00:01 UTC.

Dalli could still raise or log a warning when you set an expiry that's
interpreted as being in the past, but I can see how you wouldn't want to go
there.

Do you think you might accept a pull request that mentions this in the
Dalli README, then?


Reply to this email directly or view it on GitHubhttps://github.com//issues/251#issuecomment-7677137.

@henrik
Copy link
Author

henrik commented Aug 12, 2012

Yeah, realized that just after I sent it. Thanks for your time; will try to get around to that pull request.

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

No branches or pull requests

2 participants