Sha256: 9972be2b156c0eb040c068044a81ce3871cb249187c9f9b07a36bf3db27cf11b

Contents?: true

Size: 924 Bytes

Versions: 3

Compression:

Stored size: 924 Bytes

Contents

module Cache
  module Object
    class Adapter
      attr_reader :store

      def initialize(store)
        raise "Cache Store is nil" unless store
        @store = store
      end

      def write(decorator)
        decorator.keys.each do |key|
          store.write(key, decorator.instance, expires_in: ttl)
        end
      end

      def delete(decorator)
        decorator.keys.each do |key|
          store.delete(key)
        end
      end

      def fetch(klass, id, &block)
        store.fetch(KeyGenerator.key_for_object(klass.name, id),
                    expires_in: ttl,
                    &block)
      end

      def fetch_mapping(klass, attributes, &block)
        store.fetch(KeyGenerator.key_for_mapping(klass.name, attributes),
                    expires_in: ttl,
                    &block)
      end

      private

      def ttl
        Cache::Object.configuration.ttl
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cache-object-0.0.3 lib/cache/object/adapter.rb
cache-object-0.0.2 lib/cache/object/adapter.rb
cache-object-0.0.1 lib/cache/object/adapter.rb