Module: Knuckles::Keygen
Overview
The Keygen module provides simple cache key generation. The global keygen strategy can be changed at the top level by configuring ‘Knuckles.keygen`.
Any object that responds to ‘expand_key` with a single argument can be used instead.
Instance Method Summary collapse
-
#expand_key(object) ⇒ String
Calculates a cache key for the given object.
Instance Method Details
#expand_key(object) ⇒ String
Calculates a cache key for the given object. It first attempts to use the object’s ‘cache_key` method (present on `ActiveRecord` models). It falls back to combining the object’s ‘id` and `updated_at` values.
29 30 31 32 33 34 35 |
# File 'lib/knuckles/keygen.rb', line 29 def (object) if object.respond_to?(:cache_key) object.cache_key else "#{object.class.name}/#{object.id}/#{object.updated_at.to_i}" end end |