Class: Resourceful::InMemoryCacheManager
- Inherits:
-
AbstractCacheManager
- Object
- AbstractCacheManager
- Resourceful::InMemoryCacheManager
- Defined in:
- lib/resourceful/cache_manager.rb
Overview
This is a nieve implementation of caching. Unused entries are never removed, and this may eventually eat up all your memory and cause your machine to explode.
Instance Method Summary collapse
-
#initialize ⇒ InMemoryCacheManager
constructor
A new instance of InMemoryCacheManager.
- #invalidate(uri) ⇒ Object
- #lookup(request) ⇒ Object
- #store(request, response) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryCacheManager
Returns a new instance of InMemoryCacheManager.
68 69 70 |
# File 'lib/resourceful/cache_manager.rb', line 68 def initialize @collection = Hash.new{ |h,k| h[k] = CacheEntryCollection.new} end |
Instance Method Details
#invalidate(uri) ⇒ Object
84 85 86 |
# File 'lib/resourceful/cache_manager.rb', line 84 def invalidate(uri) @collection.delete(uri) end |
#lookup(request) ⇒ Object
72 73 74 75 76 |
# File 'lib/resourceful/cache_manager.rb', line 72 def lookup(request) response = @collection[request.uri.to_s][request] response. = false if response response end |
#store(request, response) ⇒ Object
78 79 80 81 82 |
# File 'lib/resourceful/cache_manager.rb', line 78 def store(request, response) return unless response.cacheable? @collection[request.uri.to_s][request] = response end |