Sha256: 0afeac086367b31b17db1d350ca7e963f7bf5e583a2140e32ea7fcea99f3e802

Contents?: true

Size: 1.04 KB

Versions: 32

Compression:

Stored size: 1.04 KB

Contents

module Cloudinary::Cache
  class RailsCacheAdapter < CacheAdapter

    def flush_all
    end

    def get(public_id, type, resource_type, transformation, format)
      key = generate_cache_key(public_id, type, resource_type, transformation, format)
      Rails.cache.read(key)
    end

    def init
      unless defined? Rails
        raise CloudinaryException.new "Rails is required in order to use RailsCacheAdapter"
      end
    end

    def set(public_id, type, resource_type, transformation, format, value)
      key = generate_cache_key(public_id, type, resource_type, transformation, format)
      Rails.cache.write(key, value)
    end

    def fetch(public_id, type, resource_type, transformation, format)
      key = generate_cache_key(public_id, type, resource_type, transformation, format)
      Rails.cache.fetch(key, &Proc.new)
    end
    private

    def generate_cache_key(public_id, type, resource_type, transformation, format)
      Digest::SHA1.hexdigest [public_id, type, resource_type, transformation, format].reject(&:blank?)
    end

  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

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