Module: WCC::Media::Cacheable
- Included in:
- Base
- Defined in:
- lib/wcc/media/cacheable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
- #last_modified ⇒ Object (also: #updated_at)
Class Method Details
.hash_cache_key(hash) ⇒ Object
24 25 26 |
# File 'lib/wcc/media/cacheable.rb', line 24 def self.hash_cache_key(hash) Digest::SHA1.hexdigest(Marshal.dump(hash)) end |
Instance Method Details
#cache_key ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/wcc/media/cacheable.rb', line 6 def cache_key return @cache_key if @cache_key key = (headers&.fetch('Etag', nil) if respond_to?(:headers)) key ||= WCC::Media::Cacheable.hash_cache_key(raw) @cache_key = "#{self.class.name}/#{key}" end |
#last_modified ⇒ Object Also known as: updated_at
15 16 17 18 19 20 21 |
# File 'lib/wcc/media/cacheable.rb', line 15 def last_modified return @last_modified if @last_modified last_modified = (headers&.fetch('Last-Modified', nil) if respond_to?(:headers)) @last_modified = Time.parse(last_modified) if last_modified && /\S/.match(last_modified) end |