Skip to content

Instantly share code, notes, and snippets.

@derrickko
Created June 25, 2012 19:07
Show Gist options
  • Save derrickko/2990581 to your computer and use it in GitHub Desktop.
Save derrickko/2990581 to your computer and use it in GitHub Desktop.
Action caching helpers
caches_action :index, :cache_path => Proc.new {
cache_key_for_relation(current_user.received_deliveries)
}
def cache_key_for_relation(relation, order_clause)
relation = relation.reorder(order_clause)
count = relation.count
if count > 0
cache_key_for "#{relation.first.cache_key}-#{count}"
else
cache_key_for empty_key
end
end
def cache_key_for(key_name)
"#{action_name}/#{key_name}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment