Class: SimpleJSONAPIDeserializer::Resource::Cache
- Inherits:
-
Object
- Object
- SimpleJSONAPIDeserializer::Resource::Cache
- Defined in:
- lib/simple_jsonapi_deserializer/resource/cache.rb
Instance Method Summary collapse
- #cache(id, type, deserialized_resource) ⇒ Object
- #cached?(id, type) ⇒ Boolean
- #find(id, type) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
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
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 |