Class: LastModifieds
- Inherits:
-
Object
- Object
- LastModifieds
- Defined in:
- lib/restfulie/server/action_controller/trait/cacheable.rb
Instance Method Summary collapse
-
#accepts?(responder) ⇒ Boolean
default implementation that will check whether caching can be applied.
- #do_http_cache(responder, headers) ⇒ Object
- #new_record?(responder) ⇒ Boolean
Instance Method Details
#accepts?(responder) ⇒ Boolean
default implementation that will check whether caching can be applied
14 15 16 17 18 19 20 |
# File 'lib/restfulie/server/action_controller/trait/cacheable.rb', line 14 def accepts?(responder) responder.resources.flatten.select do |resource| resource.respond_to?(:updated_at) end && responder.controller.response.last_modified.nil? && !new_record?(responder) end |
#do_http_cache(responder, headers) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/restfulie/server/action_controller/trait/cacheable.rb', line 22 def do_http_cache(responder, headers) return false unless accepts?(responder) = responder.resources.flatten.select do |resource| resource.respond_to?(:updated_at) end.map do |resource| (resource.updated_at || Time.now).utc end = .max responder.controller.response.last_modified = if end |
#new_record?(responder) ⇒ Boolean
36 37 38 |
# File 'lib/restfulie/server/action_controller/trait/cacheable.rb', line 36 def new_record?(responder) responder.resource.respond_to?(:new_record?) && responder.resource.new_record? end |