Class: Memosa::Cache

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

Overview

This class is used to interact with the memoization cache.

Instance Method Summary collapse

Constructor Details

#initialize(cache) ⇒ Cache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new instance of Memosa::Cache

Parameters:

  • cache (Hash<Symbol, BasicObject>)

    the memoization cache



11
12
13
# File 'lib/memosa/cache.rb', line 11

def initialize(cache)
  @cache = cache
end

Instance Method Details

#clearself

Reset the cache

Examples:

memosa.clear

Returns:

  • (self)


33
34
35
36
# File 'lib/memosa/cache.rb', line 33

def clear
  @cache.clear
  self
end

#delete(key) ⇒ self

Delete a key from the cache

Examples:

memosa.delete(:foo)

Parameters:

  • key (Symbol)

Returns:

  • (self)


45
46
47
48
# File 'lib/memosa/cache.rb', line 45

def delete(key)
  @cache.delete(key)
  self
end

#merge!(values) ⇒ self

Add values to the cache

Examples:

memosa.merge!(foo: "bar")

Parameters:

  • values (Hash<Symbol, BasicObject>)

    the values to add to the cache.

Returns:

  • (self)


22
23
24
25
# File 'lib/memosa/cache.rb', line 22

def merge!(values)
  @cache.merge!(values)
  self
end