Module: Elephas::Providers::Base

Extended by:
ActiveSupport::Concern
Included in:
Hash, RubyOnRails
Defined in:
lib/elephas/provider.rb

Overview

The base provider, with all methods a valid provider should override.

Instance Method Summary (collapse)

Instance Method Details

- (TrueClass|FalseClass) delete(key)

Deletes a value from the cache.

Parameters:

  • key (String)

    The key to delete.

Returns:

  • (TrueClass|FalseClass)

    true if the key was in the cache, false otherwise.

Raises:

  • (ArgumentError)


38
39
40
# File 'lib/elephas/provider.rb', line 38

def delete(key)
  raise ArgumentError.new("A Elephas::Providers subclass must override this method.")
end

- (TrueClass|FalseClass) exists?(key)

Checks if a key exists in the cache.

Parameters:

  • key (String)

    The key to lookup.

Returns:

  • (TrueClass|FalseClass)

    true if the key is in the cache, false otherwise.

Raises:

  • (ArgumentError)


46
47
48
# File 'lib/elephas/provider.rb', line 46

def exists?(key)
  raise ArgumentError.new("A Elephas::Providers subclass must override this method.")
end

- (Object) now

Returns the current time for comparing with entries TTL.

Returns:

  • (Object)

    A representation of the current time.



53
54
55
# File 'lib/elephas/provider.rb', line 53

def now
  ::Time.now.to_f
end

- (Entry|NilClass) read(key)

Reads a value from the cache.

Parameters:

  • key (String)

    The key to lookup.

Returns:

  • (Entry|NilClass)

    The read value or nil.

Raises:

  • (ArgumentError)


19
20
21
# File 'lib/elephas/provider.rb', line 19

def read(key)
  raise ArgumentError.new("A Elephas::Providers subclass must override this method.")
end

- (Object) write(key, value, options = {})

Writes a value to the cache.

Parameters:

  • key (String)

    The key to associate the value with.

  • value (Object)

    The value to write. Setting a value to nil doesn't mean deleting the value.

  • options (Hash) (defaults to: {})

    A list of options for writing.

Returns:

  • (Object)

    The value itself.

Raises:

  • (ArgumentError)

See Also:



30
31
32
# File 'lib/elephas/provider.rb', line 30

def write(key, value, options = {})
  raise ArgumentError.new("A Elephas::Providers subclass must override this method.")
end