Class: HTTP::Features::Caching::InMemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/http/features/caching/in_memory_store.rb

Overview

Simple in-memory cache store backed by a Hash

Cache keys are derived from the request method and URI.

Examples:

store = InMemoryStore.new
store.store(request, entry)
store.lookup(request) # => entry

Instance Method Summary collapse

Constructor Details

#initializeInMemoryStore

Create a new empty in-memory store

Examples:

store = InMemoryStore.new


23
24
25
# File 'lib/http/features/caching/in_memory_store.rb', line 23

def initialize
  @cache = {}
end

Instance Method Details

#lookup(request) ⇒ Entry?

Look up a cached entry for a request

Examples:

store.lookup(request) # => Entry or nil

Parameters:

Returns:



35
36
37
# File 'lib/http/features/caching/in_memory_store.rb', line 35

def lookup(request)
  @cache[cache_key(request)]
end

#store(request, entry) ⇒ Entry

Store a cache entry for a request

Examples:

store.store(request, entry)

Parameters:

Returns:



48
49
50
# File 'lib/http/features/caching/in_memory_store.rb', line 48

def store(request, entry)
  @cache[cache_key(request)] = entry
end