Class: Resourceful::CacheEntryCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/resourceful/cache_manager.rb

Overview

The collection of cached entries. Nominally all the entry in a collection of this sort will be for the same resource but that is not required to be true.

Instance Method Summary collapse

Constructor Details

#initializeCacheEntryCollection

Returns a new instance of CacheEntryCollection.



144
145
146
# File 'lib/resourceful/cache_manager.rb', line 144

def initialize
  @entries = []
end

Instance Method Details

#[](request) ⇒ Resourceful::Response

Looks for an Entry that could fullfil the request. Returns nil if none was found.

Parameters:

Returns:



161
162
163
164
# File 'lib/resourceful/cache_manager.rb', line 161

def [](request)
  entry = find { |entry| entry.valid_for?(request) }
  entry.response if entry
end

#[]=(request, response) ⇒ Object

Saves an entry into the collection. Replaces any existing ones that could be used with the updated response.

Parameters:



173
174
175
176
177
178
# File 'lib/resourceful/cache_manager.rb', line 173

def []=(request, response)
  @entries.delete_if { |e| e.valid_for?(request) }
  @entries << CacheEntry.new(request, response)

  response
end

#each(&block) ⇒ Object

Iterates over the entries. Needed for Enumerable



149
150
151
# File 'lib/resourceful/cache_manager.rb', line 149

def each(&block)
  @entries.each(&block)
end