Class: Feedx::Cache::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/feedx/cache/abstract.rb

Direct Known Subclasses

Memory

Instance Method Summary collapse

Instance Method Details

#clearObject

Clears cache.



3
4
5
# File 'lib/feedx/cache/abstract.rb', line 3

def clear
  raise 'Not implemented'
end

#fetch(key, **opts) ⇒ Object

Fetches data from the cache, using the given key. The optional block will be evaluated and the result stored in the cache in the event of a cache miss.



20
21
22
23
24
25
26
27
28
29
# File 'lib/feedx/cache/abstract.rb', line 20

def fetch(key, **opts)
  value = read(key, **opts)

  if block_given?
    value ||= yield
    write(key, value, **opts) if value
  end

  value
end

#read(_key) ⇒ Object

Read reads a key.



8
9
10
# File 'lib/feedx/cache/abstract.rb', line 8

def read(_key, **)
  raise 'Not implemented'
end

#value(key) ⇒ Feedx::Abstract::Value

Returns a wrapper around a single value.

Returns:

  • (Feedx::Abstract::Value)

    returns a wrapper around a single value.



32
33
34
# File 'lib/feedx/cache/abstract.rb', line 32

def value(key)
  Feedx::Cache::Value.new(self, key)
end

#write(_key, _value) ⇒ Object

Write writes a key/value pair.



13
14
15
# File 'lib/feedx/cache/abstract.rb', line 13

def write(_key, _value, **)
  raise 'Not implemented'
end