Sha256: 16b2a8b61a2fda637b6faf4b04d873e2c76829bc22761aa6666fed8a96134a51
Contents?: true
Size: 1.25 KB
Versions: 31
Compression:
Stored size: 1.25 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) transformed_key = transform_key(key) if forward_write?(key, value, expires_in) next_store.write(transformed_key, value, expires_in) end internal_write(transformed_key, value, expires_in) 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, expires_in = nil) 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
31 entries across 31 versions & 1 rubygems