Module: TypedCache::Backend

Included in:
TypedCache::Backends::ActiveSupport, TypedCache::Backends::Memory, Decorator
Defined in:
lib/typed_cache/backend.rb

Overview

Marker mixin for concrete cache back-ends. A Backend is a Store, but the reverse is not necessarily true (decorators also include Store). By tagging back-ends with this module we can type-check and register them separately from decorators.

Back-ends should not assume they wrap another store – they are the leaf nodes that actually persist data.

Instance Method Summary collapse

Instance Method Details

#clear(**opts) ⇒ Object

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/typed_cache/backend.rb', line 68

def clear(**opts)
  raise NotImplementedError, "#{self.class} must implement #clear"
end

#delete(key, **opts) ⇒ Object

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/typed_cache/backend.rb', line 56

def delete(key, **opts)
  raise NotImplementedError, "#{self.class} must implement #delete"
end

#fetch(key, **opts, &block) ⇒ Object

Raises:

  • (NotImplementedError)


74
75
76
# File 'lib/typed_cache/backend.rb', line 74

def fetch(key, **opts, &block)
  raise NotImplementedError, "#{self.class} must implement #fetch"
end

#fetch_multi(keys, **opts, &block) ⇒ Object



80
81
82
# File 'lib/typed_cache/backend.rb', line 80

def fetch_multi(keys, **opts, &block)
  keys.to_h { |key| [key, fetch(key, **opts, &block)] }
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/typed_cache/backend.rb', line 62

def key?(key)
  raise NotImplementedError, "#{self.class} must implement #key?"
end

#read(key, **opts) ⇒ Object

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/typed_cache/backend.rb', line 32

def read(key, **opts)
  raise NotImplementedError, "#{self.class} must implement #read"
end

#read_multi(keys, **opts) ⇒ Object



38
39
40
# File 'lib/typed_cache/backend.rb', line 38

def read_multi(keys, **opts)
  keys.to_h { |key| [key, read(key, **opts)] }
end

#write(key, value, **opts) ⇒ Object

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/typed_cache/backend.rb', line 44

def write(key, value, **opts)
  raise NotImplementedError, "#{self.class} must implement #write"
end

#write_multi(values, **opts) ⇒ Object



50
51
52
# File 'lib/typed_cache/backend.rb', line 50

def write_multi(values, **opts)
  values.transform_values { |value| write(value, **opts) }
end