Sha256: 0488cd8128a1da296f33d81357813ef166e4a39aee288b3727135faec996cd00

Contents?: true

Size: 1.38 KB

Versions: 87

Compression:

Stored size: 1.38 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, expires_in: nil, persistent: true)
        transformed_key = transform_key(key)
        if persistent && forward_write?(key, value, expires_in)
          next_store.write(transformed_key, value, expires_in: expires_in)
        end

        internal_write(transformed_key, value, expires_in) if persistent || tentative?
      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 tentative?
        raise NotImplementedError
      end

      def next_store
        raise NotImplementedError
      end

      def internal_read(key)
        raise NotImplementedError
      end

      def internal_write(key, value, expires_in)
        raise NotImplementedError
      end

      def transform_key(key)
        key
      end

      def forward_write?(key, value, expires_in)
        next_store.present?
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
scrivito_sdk-1.12.0.rc2 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.12.0.rc1 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.11.0 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.11.0.rc1 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.10.0 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.10.0.rc5 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.10.0.rc4 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.10.0.rc3 app/cms/scrivito/cache/chainable.rb
scrivito_sdk-1.10.0.rc2 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.10.0.rc1 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.9.1 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.9.1.rc1 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.9.0 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.9.0.rc2 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.9.0.rc1 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.8.1 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.8.1.rc1 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.8.0 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.8.0.rc2 lib/scrivito/cache/chainable.rb
scrivito_sdk-1.8.0.rc1 lib/scrivito/cache/chainable.rb