Class: Faulty::Cache::Interface

Inherits:
Object
  • Object
show all
Defined in:
lib/faulty/cache/interface.rb

Overview

The interface required for a cache backend implementation

This is for documentation only and is not loaded

Instance Method Summary collapse

Instance Method Details

#fault_tolerant?Boolean

Can this cache backend raise an error?

If the cache backend returns false from this method, it will be wrapped in a FaultTolerantProxy, otherwise it will be used as-is.

Returns:

  • (Boolean)

    True if this cache backend is fault tolerant

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/faulty/cache/interface.rb', line 39

def fault_tolerant?
  raise NotImplementedError
end

#read(key) ⇒ Object?

Retrieve a value from the cache if available

Parameters:

  • key (String)

    The cache key

Returns:

  • (Object, nil)

    The object if present, otherwise nil

Raises:

  • If the cache backend encounters a failure



14
15
16
# File 'lib/faulty/cache/interface.rb', line 14

def read(key)
  raise NotImplementedError
end

#write(key, value, expires_in: nil) ⇒ void

This method returns an undefined value.

Write a value to the cache

This may be any object. It's up to the cache implementation to serialize if necessary or raise an error if unsupported.

Parameters:

  • key (String)

    The cache key

  • expires_in (Integer, nil) (defaults to: nil)

    The number of seconds until this cache entry expires. If nil, no expiration is set.

  • value (Object)

    The value to write to the cache

Raises:

  • If the cache backend encounters a failure



29
30
31
# File 'lib/faulty/cache/interface.rb', line 29

def write(key, value, expires_in: nil)
  raise NotImplementedError
end