Class: Rod::Rest::ProxyCache

Inherits:
Object
  • Object
show all
Defined in:
lib/rod/rest/proxy_cache.rb

Overview

Cache used to store proxy objects.

Instance Method Summary collapse

Constructor Details

#initialize(cache_implementation = {}) ⇒ ProxyCache

Initializes empty cache.



8
9
10
# File 'lib/rod/rest/proxy_cache.rb', line 8

def initialize(cache_implementation={})
  @cache_implementation = cache_implementation
end

Instance Method Details

#[](description) ⇒ Object

Returns the object stored in the cache. Raises CacheMissed exception if the result is nil.

Raises:



20
21
22
23
24
# File 'lib/rod/rest/proxy_cache.rb', line 20

def [](description)
  check_description(description)
  value = @cache_implementation[description_signature(description)]
  raise CacheMissed.new(missing_entry_message(description)) if value.nil?
end

#has_key?(description) ⇒ Boolean

Returns true if the described object is in the cache.

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/rod/rest/proxy_cache.rb', line 13

def has_key?(description)
  check_description(description)
  @cache_implementation[description_signature(description)]
end

#store(object) ⇒ Object

Store the object in the cache.



27
28
29
30
# File 'lib/rod/rest/proxy_cache.rb', line 27

def store(object)
  check_object(object)
  @cache_implementation[description_signature(rod_id: object.rod_id,type: object.type)] = object
end