module AllCacheKey | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def cache_key | |
pluck("COUNT(*)", "MAX(updated_at)").flatten.map(&:to_i).join("-") | |
end | |
end | |
end |
This comment has been minimized.
This comment has been minimized.
This is similar to Caching with Rails guide |
This comment has been minimized.
This comment has been minimized.
For Rails 3 you need a little bit more code: def cache_key
sql = select('COUNT(*), MAX(updated_at)').to_sql
connection.execute(sql).to_a.flatten.map(&:to_i).join('-')
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Note the multi-valued pluck is a Rails 4 feature, Rails 3 will need something slightly different