Class: SimpleJSONAPIDeserializer::Resource::Cache

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

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



4
5
6
# File 'lib/simple_jsonapi_deserializer/resource/cache.rb', line 4

def initialize
  @cached_resources = {}
end

Instance Method Details

#cache(id, type, deserialized_resource) ⇒ Object



8
9
10
11
# File 'lib/simple_jsonapi_deserializer/resource/cache.rb', line 8

def cache(id, type, deserialized_resource)
  cached_resources[type] ||= {}
  cached_resources[type][id] = deserialized_resource
end

#cached?(id, type) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/simple_jsonapi_deserializer/resource/cache.rb', line 13

def cached?(id, type)
  cached_resource(id, type)
end

#find(id, type) ⇒ Object



17
18
19
# File 'lib/simple_jsonapi_deserializer/resource/cache.rb', line 17

def find(id, type)
  cached_resources.dig(type, id)
end