Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module AllCacheKey
extend ActiveSupport::Concern
module ClassMethods
def cache_key
pluck("COUNT(*)", "MAX(updated_at)").flatten.map(&:to_i).join("-")
end
end
end
@aaronjensen

This comment has been minimized.

Copy link
Owner Author

commented Jul 23, 2013

Note the multi-valued pluck is a Rails 4 feature, Rails 3 will need something slightly different

@tortuetorche

This comment has been minimized.

Copy link

commented Jul 26, 2013

This is similar to Caching with Rails guide cache_key_for_products method, isn't it ?
Or i'ts more optimized ?

@ream88

This comment has been minimized.

Copy link

commented Sep 11, 2013

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
You can’t perform that action at this time.