Class: Tina4::CacheBackends::BaseBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/tina4/cache_backends/base_backend.rb

Overview

Abstract cache backend (parity with Python _CacheBackend).

A backend is a key/value store with TTL semantics and stats. Values are arbitrary JSON-serialisable objects; backends round-trip them through JSON for the network/file/db tiers so a value stored by one process can be read by another. The factory (Tina4::CacheBackends.create_backend) picks the right implementation from env vars and falls back to the file backend when a configured network/driver backend is unreachable.

Instance Method Summary collapse

Instance Method Details

#available?Boolean

Whether this backend is actually usable (driver present + service reachable). Local backends are always available; network/driver backends override this so the factory can fall back to the file backend.

Returns:

  • (Boolean)


53
54
55
# File 'lib/tina4/cache_backends/base_backend.rb', line 53

def available?
  true
end

#clearObject

Remove all entries owned by this cache.

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/tina4/cache_backends/base_backend.rb', line 34

def clear
  raise NotImplementedError
end

#delete(_key) ⇒ Boolean

Returns true if the key existed.

Parameters:

  • key (String)

Returns:

  • (Boolean)

    true if the key existed

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/tina4/cache_backends/base_backend.rb', line 29

def delete(_key)
  raise NotImplementedError
end

#get(_key) ⇒ Object?

Returns cached value or nil on miss/expiry.

Parameters:

  • key (String)

Returns:

  • (Object, nil)

    cached value or nil on miss/expiry

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/tina4/cache_backends/base_backend.rb', line 16

def get(_key)
  raise NotImplementedError
end

#nameString

Returns backend name reported in stats.

Returns:

  • (String)

    backend name reported in stats

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/tina4/cache_backends/base_backend.rb', line 44

def name
  raise NotImplementedError
end

#set(_key, _value, _ttl) ⇒ Object

Parameters:

  • key (String)
  • value (Object)
  • ttl (Integer)

    seconds; <= 0 means no expiry

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/tina4/cache_backends/base_backend.rb', line 23

def set(_key, _value, _ttl)
  raise NotImplementedError
end

#statsHash

Returns { hits:, misses:, size:, backend: }.

Returns:

  • (Hash)

    { hits:, misses:, size:, backend: }

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/tina4/cache_backends/base_backend.rb', line 39

def stats
  raise NotImplementedError
end