Sha256: ef6a73ce069c614b820210e5edd4b494f91275ac52d114454fc26695ad669cdc

Contents?: true

Size: 745 Bytes

Versions: 4

Compression:

Stored size: 745 Bytes

Contents

module WCC
  module Media
    module Cacheable
      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

      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
      alias_method :updated_at, :last_modified

      def self.hash_cache_key(hash)
        Digest::SHA1.hexdigest(Marshal.dump(hash))
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wcc-media-client-0.4.15 lib/wcc/media/cacheable.rb
wcc-media-client-0.4.14 lib/wcc/media/cacheable.rb
wcc-media-client-0.4.13 lib/wcc/media/cacheable.rb
wcc-media-client-0.4.12 lib/wcc/media/cacheable.rb