Class: Endpointer::Cacher
- Inherits:
-
Object
- Object
- Endpointer::Cacher
- Defined in:
- lib/endpointer/cacher.rb
Instance Method Summary collapse
- #get(resource) ⇒ Object
-
#initialize(path) ⇒ Cacher
constructor
A new instance of Cacher.
- #invalidate ⇒ Object
- #set(resource, response) ⇒ Object
Constructor Details
#initialize(path) ⇒ Cacher
Returns a new instance of Cacher.
9 10 11 |
# File 'lib/endpointer/cacher.rb', line 9 def initialize(path) initialize_path(path) end |
Instance Method Details
#get(resource) ⇒ Object
13 14 15 16 17 |
# File 'lib/endpointer/cacher.rb', line 13 def get(resource) cache_container = retrieve_cache_container(resource) raise Endpointer::Errors::CachedItemNotFoundError unless cache_container.resource == resource cache_container.response end |
#invalidate ⇒ Object
24 25 26 27 |
# File 'lib/endpointer/cacher.rb', line 24 def invalidate FileUtils.remove_entry(@path) initialize_path(@path) end |
#set(resource, response) ⇒ Object
19 20 21 22 |
# File 'lib/endpointer/cacher.rb', line 19 def set(resource, response) cache_container = create_cache_container(resource, response) File.write(File.join(@path, "#{resource.id}.yml"), YAML.dump(cache_container)) end |