lib/grape/app/helpers/caching.rb in grape-app-0.8.4 vs lib/grape/app/helpers/caching.rb in grape-app-0.8.5

- old
+ new

@@ -15,18 +15,17 @@ # fresh_when(article, public: true) # # article # end # - def fresh_when(object=nil, etag: nil, last_modified: nil, **cache_control) + def fresh_when(object = nil, etag: nil, last_modified: nil, last_modified_field: :updated_at, **cache_control) etag ||= object - last_modified ||= object.try(:updated_at) || object.try(:maximum, :updated_at) - + last_modified = object.try(last_modified_field) || object.try(:maximum, last_modified_field) if last_modified.nil? etag = ActiveSupport::Digest.hexdigest(ActiveSupport::Cache.expand_cache_key(etag)) header 'ETag', etag header 'Last-Modified', last_modified.httpdate if last_modified - cache_control(cache_control) unless cache_control.empty? + cache_control(**cache_control) unless cache_control.empty? if_modified_since = headers['If-Modified-Since'] if_modified_since = Time.rfc2822(if_modified_since) rescue nil if if_modified_since # rubocop:disable Style/RescueModifier if_none_match = headers['If-None-Match'] return unless if_modified_since || if_none_match @@ -47,10 +46,10 @@ # get '/articles/:id' do # article = Article.find(params[:id]) # stats = article.really_expensive_call if stale?(article) # end # - def stale?(object=nil, **freshness_opts) + def stale?(object = nil, **freshness_opts) fresh_when(object, **freshness_opts) true end # Sets an HTTP 1.1 Cache-Control header. Defaults to `private`.