Sha256: 5277676538b829b48eb1a0eda854f32b2c9d8e39857fab4a3e28d740321e8011

Contents?: true

Size: 964 Bytes

Versions: 32

Compression:

Stored size: 964 Bytes

Contents

require 'digest'

module Cloudinary
  module Cache

    class << self
      attr_accessor :storage

      def get(public_id, options)
        if block_given?
          storage.read(generate_cache_key(public_id, options)) {yield}
        else
          storage.read(generate_cache_key(public_id, options))
        end
      end

      def set(public_id, options, value)
        storage.write(generate_cache_key(public_id, options), value)
      end

      alias_method :fetch, :get

      def flush_all
        storage.clear
      end

      private

      def generate_cache_key(public_id, options)
        type = options[:type] || "upload"
        resource_type = options[:resource_type] || "image"
        transformation = Cloudinary::Utils.generate_transformation_string options.clone
        format = options[:format]
        Digest::SHA1.hexdigest [public_id, type, resource_type, transformation, format].reject(&:blank?).join('/')
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
cloudinary-2.2.0 lib/cloudinary/cache.rb
cloudinary-2.1.2 lib/cloudinary/cache.rb
cloudinary-2.0.2 lib/cloudinary/cache.rb
cloudinary-2.0.1 lib/cloudinary/cache.rb
cloudinary-2.0.0 lib/cloudinary/cache.rb
cloudinary-1.29.0 lib/cloudinary/cache.rb
cloudinary-1.28.0 lib/cloudinary/cache.rb
cloudinary-1.27.0 lib/cloudinary/cache.rb
cloudinary-1.26.0 lib/cloudinary/cache.rb
cloudinary-1.25.0 lib/cloudinary/cache.rb
cloudinary-1.24.0 lib/cloudinary/cache.rb
cloudinary-1.23.0 lib/cloudinary/cache.rb
cloudinary-1.22.0 lib/cloudinary/cache.rb
cloudinary-1.21.0 lib/cloudinary/cache.rb
cloudinary-1.20.0 lib/cloudinary/cache.rb
cloudinary-1.19.0 lib/cloudinary/cache.rb
cloudinary-1.18.1 lib/cloudinary/cache.rb
cloudinary-1.18.0 lib/cloudinary/cache.rb
cloudinary-1.17.1 lib/cloudinary/cache.rb
cloudinary-1.17.0 lib/cloudinary/cache.rb