Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F906825
http_cache_responder.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 30, 10:52 AM
Size
1 KB
Mime Type
text/x-ruby
Expires
Mon, Sep 1, 10:52 AM (19 h, 16 m)
Engine
blob
Format
Raw Data
Handle
253648
Attached To
rWEBDNS WebDNS (edet4)
http_cache_responder.rb
View Options
module
Responders
# Set HTTP Last-Modified headers based on the given resource. It's used only
# on API behavior (to_format) and is useful for a client to check in the server
# if a resource changed after a specific date or not.
#
# This is not usually not used in html requests because pages contains a lot
# information besides the resource information, as current_user, flash messages,
# widgets... that are better handled with other strategies, as fragment caches and
# the digest of the body.
#
module
HttpCacheResponder
def
initialize
(
controller
,
resources
,
options
=
{})
super
@http_cache
=
options
.
delete
(
:http_cache
)
end
def
to_format
return
if
do_http_cache?
&&
do_http_cache!
super
end
protected
def
do_http_cache!
timestamp
=
resources
.
map
do
|
resource
|
resource
.
updated_at
.
try
(
:utc
)
if
resource
.
respond_to?
(
:updated_at
)
end
.
compact
.
max
controller
.
response
.
last_modified
||=
timestamp
if
timestamp
head
:not_modified
if
fresh
=
request
.
fresh?
(
controller
.
response
)
fresh
end
def
do_http_cache?
get?
&&
@http_cache
!=
false
&&
ActionController
::
Base
.
perform_caching
&&
persisted?
&&
resourceful?
&&
resource
.
respond_to?
(
:updated_at
)
end
def
persisted?
resource
.
respond_to?
(
:persisted?
)
?
resource
.
persisted?
:
true
end
end
end
Event Timeline
Log In to Comment