-
-
Notifications
You must be signed in to change notification settings - Fork 115
Cache Control #14
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
Cache Control #14
Conversation
Or, alternative idea. How would one do this as an extension to lotus/controller? |
@karlfreeman Thanks for the idea, it's definitely something needed, but not enabled by default (see Anyway, because I'm focused on releasing Lotus right now, I suggest to merge this after lotus-controller 0.2.0 will be out. Maybe targeting the 0.2.1. What do you think? |
@karlfreeman Why do you want to open a different issue? We'll merge this once ready and Lotus will be releases. |
@jodosha The reason was mainly as this is a pull request linked to my feature branch instead of being an issue which can be "closed" via a pull request. Doesnt matter really 😄. |
@karlfreeman This PR needs some ❤️
Do you still want to take care of this? |
Yeah, on this. Went AWOL for a couple days. Will bolster tests, documentation and generally put more time into this. What's your thoughts of including Timecop or should we follow ActiveSupports lead with |
@karlfreeman Is Minitest's stub enough? |
@jodosha Ok, as I'm just freezing eg: describe 'Cache control' do
before do
@app = Rack::MockRequest.new(CacheControlRoutes)
end
around do |test|
Time.stub(:now, Time.now) do
test.call
end
end
it 'accepts a Symbol' do
response = @app.get('/symbol')
response.headers.fetch('Cache-Control').must_equal('private')
end
it 'accepts multiple Symbols' do
response = @app.get('/symbols')
response.headers.fetch('Cache-Control').split(', ').must_equal %w(private no-store)
end
end vs describe 'Cache control' do
before do
@app = Rack::MockRequest.new(CacheControlRoutes)
end
it 'accepts a Symbol' do
Time.stub(:now, Time.now) do
response = @app.get('/symbol')
response.headers.fetch('Cache-Control').must_equal('private')
end
end
it 'accepts multiple Symbols' do
Time.stub(:now, Time.now) do
response = @app.get('/symbols')
response.headers.fetch('Cache-Control').split(', ').must_equal %w(private no-store)
end
end
end |
@karlfreeman 👍 for the second. |
Ok. No problem. Some previous cargo-cult thinking was when calling require 'lotus/controller'
require 'lotus/action/cache_control'
class CacheControlController
include Lotus::Controller
include Lotus::Action::CacheControl
action 'RandomPrivate' do
def call(params)
is_private = [TRUE, FALSE].sample
# set Cache-Control directives
cache_control :public, :no_store, max_age: 900
if is_private
# merge more Cache-Control directives
cache_control :private, max_age: 90
end
# Cache-Control: private, no-store, max-age=90
end
end
action 'SometimesCachable' do
def call(params)
is_super_cachable = [TRUE, FALSE].sample
# set Cache-Control directives
cache_control :private, :no_cache, :no_store
if is_super_cachable
# somehow remove previous Cache-Control directives?
cache_control :public, max_age: 900
end
# Cache-Control: public, no-cache, no_store, max-age=900
end
end
end The Sinatra keeps it simple by always overwriting your previous |
@karlfreeman Interesting, I haven't considered it yet, probably the second case is less confusing and respects POLA. What's your opinion about having a DSL for this? It would keep module ArticlesController
include Lotus::Controller
action 'Create' do
include Lotus::Action
cache_control :private, :must_revalidate, max_age: 0
def call(params)
@article = Article.new(params)
ArticleRepository.persist(@article)
end
end
end |
Hey guys, which brach this code is available? I want to help with some |
@lucasas https://github.com/karlfreeman/controller/tree/feature/cache-control |
Sorry about this. Snowed under till the weekend :/. |
Of course @jodosha, I'll take care of cache control. I'm gonna fork @karlfreeman repository and start to work on it today. Is it ok for you @karlfreeman? |
Hey @jodosha. I've done some refactoring and included missing First question is: Should I create a new PR into @karlfreeman repository or create another one into lotus/repository? |
@lucasas Please open at |
Closing in favor of #36 |
Having previously looked into Grape I was a little dis-heartened to find it had no cache-control helpers built in. So I went ahead and implemented them. Given that I had the relatively simple logic to hand I figured I'd see what it looked like in Lotus.
We could have a combination of both types of methods?
A WIP, hence the complete lack of documentation / nice code 🍺.