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

Expiration value could indicate clearer the two different modes (interval vs timestamp) #73

Open
adam-26 opened this issue Nov 20, 2015 · 3 comments

Comments

@adam-26
Copy link

adam-26 commented Nov 20, 2015

Hi,
I was attempting to set the TTL value in milliseconds instead of seconds using the SET method. The value i was using for TTL was 1 hour. The SET command would complete without error, but any following GET requests could not find the data. After realizing the method expects TTL in seconds, everything worked as expected.

What is the maximum permitted TTL value? I know this is my own fault for not reading the documentation more closely, but it would be nice to receive an error message if the TTL value is invalid instead of silently failing.

Cheers, Adam.

@alevy
Copy link
Member

alevy commented Dec 1, 2015

So, memjs just passes along the value to memcache. There actually isn't a maximum TTL value in memcache. However, anything over 30 days (2592000 seconds) is treated as an absolute epoch time (seconds since Unix 1970). The documentation for Client#create describes this.

All ears if you think there is a good way to reflect this in the API, though!

@adam-26
Copy link
Author

adam-26 commented Dec 2, 2015

Could you inspect the TTL, and if over the 30 day limit, return an error if the epoch is in the past (before now)? If you are caching with a TTL, defining an expiry date in the past doesn't make a lot of sense.

@alevy
Copy link
Member

alevy commented Dec 2, 2015

That's a possibility. I see a couple issues with that:

  1. The semantics of the TTL are to use the clock of the server running memcache, while checking on the client-side would have to use the local clock, which may not be synchronized. So it's not unreasonable that by trying to validate the TTL on the client would result in an incorrect error.
  2. The behavior of memcache is not to return an error if the TTL is in the past. This could very well be behavior that a user exploits (for example, to elide a test for the validity of some value when setting it, and just letting memcache do that work).

This seems like an unfortunate choice of the memcache protocol, but a choice we need to live with. This is a command that accepts two types of parameters, that happen to have the same type, without anything in the protocol to differentiate what the caller means (and an arbitrary cutoff point).

I'd be open, instead to adding some type information to commands that accept a TTL to help a user be explicit about their choices. For example, I can imagine the TTL value taking an object that is either an Interval or a Timestamp and converting it to an integer for memcache accordingly. It'd just have to do this in a backwards compatible way...

@dterei dterei changed the title Set TTL issue Expiration value could indicate clearer the two different modes (interval vs timestamp) Apr 19, 2016
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