Sha256: 26752e3a130f36b2e759b05c9561698cbcda71f3d8195aa647425f4aa4704145

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 KB

Contents

module Scrivito
  module Cache
    module Chainable
      def read(key)
        transformed_key = transform_key(key)
        value = internal_read(transformed_key)
        if !value && next_store
          value = next_store.read(transformed_key)
          internal_write(transformed_key, value)
        end
        value
      end

      def write(key, value, options = {})
        transformed_key = transform_key(key)
        next_store.write(transformed_key, value, options) if next_store
        internal_write(transformed_key, value, options)
      end

      def fetch(key, &block)
        read(key) || block.call.tap { |value| write(key, value) }
      end

      def clear
        raise NotImplementedError
      end

      def clear_all
        clear
        next_store.clear if next_store
      end

      private

      def next_store
        raise NotImplementedError
      end

      def internal_read(key)
        raise NotImplementedError
      end

      def internal_write(key, value, options = {})
        raise NotImplementedError
      end

      def transform_key(key)
        key
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
scrivito_sdk-0.50.1 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.50.0 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.50.0.rc2 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.50.0.rc1 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.42.1 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.42.1.rc3 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.42.1.rc2 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.42.1.rc1 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.42.0 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.41.1 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.41.0 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.41.0.rc2 lib/scrivito/cache/chainable.rb
scrivito_sdk-0.41.0.rc1 lib/scrivito/cache/chainable.rb