-
Notifications
You must be signed in to change notification settings - Fork 119
Metastore TTL support #117
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
Changes from 3 commits
9a53093
fb529ef
dc587dd
b2ed0a7
aeb250d
3caa6f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,4 +124,13 @@ which will act as the cache key generator: | |
| end | ||
|
|
||
| For more options see the [Rack::Request documentation](http://rack.rubyforge.org/doc/classes/Rack/Request.html) | ||
|
|
||
|
|
||
| ### `use_native_ttl` | ||
|
|
||
| Passes on the expiration timestamp to the cache store. This may be necessary | ||
| with some stores to keep them from filling up, e.g. if using a Redis backend and | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you wrote your own redis backend ? ... want to link that in the readme ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I didn't. This PR is mainly about making
Sure thing.
Not sure what you mean? To my understanding (edit: markdown)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is entity and meta store ... and there should be no reason On Tue, Feb 2, 2016 at 12:32 AM, Julien Letessier notifications@github.com
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd agree with you... mostly. We've been bitten by the fact the current Rack::Cache doesn't support dependency-injecting one's store (except with the kludgy hack for Memcache), because that causes 2 extra connections per process to the backend to be created (Redis, in our case). Not ideal scaling wise. But, most users (at small scale) probably appreciate the simplicity of the current interface? As in, provide a URL and be done with it — no need to instantiate your own store.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (also, going off-topic. Sorry. I'll get back to fixing this PR.) |
||
| the `volatile-ttl` expiration policy. | ||
|
|
||
| If using `memcached`, it will speed up misses slightly as the middleware won't | ||
| need to fetch metadata and check timestamps. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,11 @@ def store(request, response, entity_store) | |
| headers.delete 'Age' | ||
|
|
||
| entries.unshift [stored_env, headers] | ||
| write key, entries | ||
| if request.env['rack-cache.use_native_ttl'] && response.fresh? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this be better as an option when creating the store ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It might, but I was trying to keep this PR about the bug fix — the I'm happy to make this a store option, but as that would be a breaking change (some users have code that reliad on
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, did not know that, sounds good then! On Tue, Feb 2, 2016 at 12:38 AM, Julien Letessier notifications@github.com
|
||
| write key, entries, response.ttl | ||
| else | ||
| write key, entries | ||
| end | ||
| key | ||
| end | ||
|
|
||
|
|
@@ -155,7 +159,7 @@ def read(key) | |
| # Store an Array of request/response pairs for the given key. Concrete | ||
| # implementations should not attempt to filter or concatenate the | ||
| # list in any way. | ||
| def write(key, negotiations) | ||
| def write(key, negotiations, ttl = nil) | ||
| raise NotImplementedError | ||
| end | ||
|
|
||
|
|
@@ -188,7 +192,7 @@ def read(key) | |
| end | ||
| end | ||
|
|
||
| def write(key, entries) | ||
| def write(key, entries, ttl = nil) | ||
| @hash[key] = Marshal.dump(entries) | ||
| end | ||
|
|
||
|
|
@@ -226,7 +230,7 @@ def read(key) | |
| [] | ||
| end | ||
|
|
||
| def write(key, entries) | ||
| def write(key, entries, ttl = nil) | ||
| tries = 0 | ||
| begin | ||
| path = key_path(key) | ||
|
|
@@ -325,9 +329,9 @@ def read(key) | |
| cache.get(key) || [] | ||
| end | ||
|
|
||
| def write(key, entries) | ||
| def write(key, entries, ttl = 0) | ||
| key = hexdigest(key) | ||
| cache.set(key, entries) | ||
| cache.set(key, entries, ttl) | ||
| end | ||
|
|
||
| def purge(key) | ||
|
|
@@ -359,9 +363,9 @@ def read(key) | |
| [] | ||
| end | ||
|
|
||
| def write(key, entries) | ||
| def write(key, entries, ttl = 0) | ||
| key = hexdigest(key) | ||
| cache.set(key, entries) | ||
| cache.set(key, entries, ttl) | ||
| end | ||
|
|
||
| def purge(key) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like
that support it, like memcached and rediscould be good to not make ppl think heap/file support it ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix.