grape-rails-cache icon indicating copy to clipboard operation
grape-rails-cache copied to clipboard

default to cache_key

Open gottfrois opened this issue 10 years ago • 0 comments

Any reason why you are not using cache_key instance method by default?

post = Post.find(params[:id])
cache(key: post.cache_key, etag: post.updated_at, expires_in: 2.hours) do
  post # post.extend(PostRepresenter) etc, any code that renders response
end

post.cache_key could also be used to generate etag since the key already includes the updated_at.

This would allow a nicer API:

post = Post.find(params[:id])
cache(post, expires_in: 2.hours) do
  post # post.extend(PostRepresenter) etc, any code that renders response
end

gottfrois avatar Nov 03 '15 15:11 gottfrois