Class: HTTP::Features::Caching::InMemoryStore
- Inherits:
-
Object
- Object
- HTTP::Features::Caching::InMemoryStore
- Defined in:
- lib/http/features/caching/in_memory_store.rb,
sig/http.rbs
Overview
Simple in-memory cache store backed by a Hash
Cache keys are derived from the request method and URI.
Instance Method Summary collapse
-
#cache_key(request) ⇒ String
private
Compute the cache key for a request.
-
#initialize ⇒ InMemoryStore
constructor
Create a new empty in-memory store.
-
#lookup(request) ⇒ Entry?
Look up a cached entry for a request.
-
#store(request, entry) ⇒ Entry
Store a cache entry for a request.
Constructor Details
#initialize ⇒ InMemoryStore
Create a new empty in-memory store
23 24 25 |
# File 'lib/http/features/caching/in_memory_store.rb', line 23 def initialize @cache = {} end |
Instance Method Details
#cache_key(request) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compute the cache key for a request
57 58 59 |
# File 'lib/http/features/caching/in_memory_store.rb', line 57 def cache_key(request) format("%s %s", request.verb, request.uri) end |
#lookup(request) ⇒ Entry?
Look up a cached entry for a request
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
48 49 50 |
# File 'lib/http/features/caching/in_memory_store.rb', line 48 def store(request, entry) @cache[cache_key(request)] = entry end |