Class: HTTP::Session::Cache
- Inherits:
-
Object
- Object
- HTTP::Session::Cache
- Includes:
- MonitorMixin
- Defined in:
- lib/http/session/cache.rb,
lib/http/session/cache/entry.rb,
lib/http/session/cache/status.rb,
lib/http/session/cache/cache_control.rb
Defined Under Namespace
Classes: CacheControl, Entry, Status
Instance Method Summary collapse
-
#initialize(options) ⇒ Cache
constructor
A new instance of Cache.
-
#private? ⇒ Boolean
True when it is a private cache.
-
#read(req) ⇒ Entry
Read an entry from cache.
-
#shared? ⇒ Boolean
True when it is a shared cache.
-
#write(req, res) ⇒ void
Write an entry to cache.
Constructor Details
#initialize(options) ⇒ Cache
Returns a new instance of Cache.
6 7 8 9 10 |
# File 'lib/http/session/cache.rb', line 6 def initialize() super() @options = end |
Instance Method Details
#private? ⇒ Boolean
True when it is a private cache.
46 47 48 |
# File 'lib/http/session/cache.rb', line 46 def private? @options.private_cache? end |
#read(req) ⇒ Entry
Read an entry from cache.
16 17 18 19 20 21 22 |
# File 'lib/http/session/cache.rb', line 16 def read(req) synchronize do key = cache_key_for(req) entries = read_entries(key) entries.find { |e| entry_matched?(e, req) } end end |
#shared? ⇒ Boolean
True when it is a shared cache.
41 42 43 |
# File 'lib/http/session/cache.rb', line 41 def shared? @options.shared_cache? end |
#write(req, res) ⇒ void
This method returns an undefined value.
Write an entry to cache.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/http/session/cache.rb', line 29 def write(req, res) synchronize do key = cache_key_for(req) entries = read_entries(key) entries = entries.reject { |e| entry_matched?(e, req) } entry = HTTP::Session::Cache::Entry.new(req, res) entries << entry write_entries(key, entries) end end |