23. 1?GJQQMJTCQRFGQNPM@JCKUGRFA?AFCBGECQRQ
A call to #cache in your views will now suffix a digest of the template and its
dependencies. No longer will you need to worry about fragment cache
dependencies and versioning!
user.cache_key
= users/1-20141002181257446781000
Read fragment views/users/1-20141002181257446781000/
95a652b13f0fc5b7bc8785ac31b6b8b9 (1.2ms)
22 / 58
24. 1?GJQQMJTCQRFGQNPM@JCKUGRFA?AFCBGECQRQ
A call to #cache in your views will now suffix a digest of the template and its
dependencies. No longer will you need to worry about fragment cache
dependencies and versioning!
user.cache_key
= users/1-20141002181257446781000
Read fragment views/users/1-20141002181257446781000/
95a652b13f0fc5b7bc8785ac31b6b8b9 (1.2ms)
23 / 58
25. 1?GJQQMJTCQRFGQNPM@JCKUGRFA?AFCBGECQRQ
A call to #cache in your views will now suffix a digest of the template and its
dependencies. No longer will you need to worry about fragment cache
dependencies and versioning!
user.cache_key
= users/1-20141002181257446781000
Read fragment views/users/1-20141002181257446781000/
95a652b13f0fc5b7bc8785ac31b6b8b9 (1.2ms)
There's a gem for that
rails/cache_digests
24 / 58
34. 2MJSRGMLQ
,MTCGRAJGCLRQGBC
.event-pod{data-wishlisted=#{
wishlisted_label(activity, current_user)}}
$('.event-pod').each(function(){
$(this).find('.wishlisted_button').html(
$(this.data('wishlisted'))
);
})
???
This is good if you want to decouple the usere data or generate it in
Also good for edge caching.
*extra complexity
33 / 58
41. def show
@article = Article.find(params[:id])
if stale?(:etag = @article, :last_modified
= @article.created_at.utc)
@statistics = @article.really_expensive_call
respond_to do |format|
# all the supported formats
end
end
end
40 / 58
42. def show
@article = Article.find(params[:id])
if stale?(:etag = @article, :last_modified
= @article.created_at.utc)
@statistics = @article.really_expensive_call
respond_to do |format|
# all the supported formats
end
end
end
41 / 58
43. def show
@article = Article.find(params[:id])
if stale?(:etag = @article, :last_modified
= @article.created_at.utc)
@statistics = @article.really_expensive_call
respond_to do |format|
# all the supported formats
end
end
end
= 304 Not Modified
42 / 58
46. Cache-Control: public - Any cache can store a copy of the content.
Cache-Control: private - Don't store, this is for a single user.
Cache-Control: no-cache - Re-validate before serving this content.
Cache-Control: no-store - Don't store this content. Ever. At all. Please.
Cache-Control: public, max-age=[seconds] - Caches can store this content for n
seconds.
Cache-Control: s-maxage=[seconds] - Same as max-age but applies specifically
to proxy
45 / 58
48. class SuggestionsController
def show
@users = Rails.cache.fetch(['users', params['page']]) do
# we need to call .all to hit the database otherwise
# we cache only the ruby query object
User.suggestions.page(params['page']).all
end
end
end
*all is for rails3
47 / 58
52. 3?E@?QCBA?AFGLE
Instead of using updated_at to cause a cache miss, record where your objects
are cached
cache @something, tag: ['dashboard', 'settings']
@users = Rails.cache.fetch(['users', params['page']],
tag: 'users') do
# we need to call .all to hit the database otherwise
# we cache only the ruby query object
User.suggestions.page(params['page']).all
end
...
User#after_commit
...
Cashier.expire users
51 / 58