Module: Vident::Caching::CacheKey
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/vident/caching/cache_key.rb
Instance Method Summary collapse
- #cache_key_modifier ⇒ Object
- #cache_keys_for_sources(key_attributes) ⇒ Object
- #cacheable? ⇒ Boolean
-
#component_modified_time ⇒ Object
Component modified time which is combined with other cache key attributes to generate cache key for an instance.
- #generate_cache_key(index) ⇒ Object
- #generate_item_cache_key_from(item) ⇒ Object
Instance Method Details
#cache_key_modifier ⇒ Object
129 130 131 |
# File 'lib/vident/caching/cache_key.rb', line 129 def cache_key_modifier ENV["RAILS_CACHE_ID"] end |
#cache_keys_for_sources(key_attributes) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/vident/caching/cache_key.rb', line 133 def cache_keys_for_sources(key_attributes) sources = key_attributes.flat_map { |n| n.is_a?(Proc) ? instance_eval(&n) : send(n) } sources.compact.map do |item| next if item == self generate_item_cache_key_from(item) end end |
#cacheable? ⇒ Boolean
125 126 127 |
# File 'lib/vident/caching/cache_key.rb', line 125 def cacheable? respond_to? :cache_key end |
#component_modified_time ⇒ Object
Component modified time which is combined with other cache key attributes to generate cache key for an instance
121 122 123 |
# File 'lib/vident/caching/cache_key.rb', line 121 def component_modified_time self.class.component_modified_time end |
#generate_cache_key(index) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/vident/caching/cache_key.rb', line 153 def generate_cache_key(index) key_attributes = self.class.named_cache_key_attributes[index] return nil unless key_attributes key = "#{self.class.name}/#{cache_keys_for_sources(key_attributes).join("/")}" raise StandardError, "Cache key for key #{key} is blank!" if key.blank? @cache_key[index] = cache_key_modifier.present? ? "#{key}/#{cache_key_modifier}" : key end |
#generate_item_cache_key_from(item) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/vident/caching/cache_key.rb', line 141 def generate_item_cache_key_from(item) if item.respond_to? :cache_key_with_version item.cache_key_with_version elsif item.respond_to? :cache_key item.cache_key elsif item.is_a?(String) Digest::SHA1.hexdigest(item) else Digest::SHA1.hexdigest(Marshal.dump(item)) end end |