Class: HTTP::Session::Cache
- Inherits:
-
Object
- Object
- HTTP::Session::Cache
- Extended by:
- Forwardable
- 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
-
#enabled? ⇒ Boolean
True when it is enabled.
-
#initialize(options) ⇒ Cache
constructor
A new instance of Cache.
-
#private_cache? ⇒ Boolean
True when it is a private cache.
-
#read(req) ⇒ nil, Entry
Read an entry from cache.
-
#shared_cache? ⇒ 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.
22 23 24 25 |
# File 'lib/http/session/cache.rb', line 22 def initialize() super() @options = end |
Instance Method Details
#enabled? ⇒ Boolean
True when it is enabled.
9 |
# File 'lib/http/session/cache.rb', line 9 def_delegator :@options, :enabled? |
#private_cache? ⇒ Boolean
True when it is a private cache.
19 |
# File 'lib/http/session/cache.rb', line 19 def_delegator :@options, :private_cache? |
#read(req) ⇒ nil, Entry
Read an entry from cache.
31 32 33 34 35 36 37 |
# File 'lib/http/session/cache.rb', line 31 def read(req) synchronize do key = cache_key_for(req) entries = read_entries(key) entries.find { |e| entry_matched?(e, req) } end end |
#shared_cache? ⇒ Boolean
True when it is a shared cache.
14 |
# File 'lib/http/session/cache.rb', line 14 def_delegator :@options, :shared_cache? |
#write(req, res) ⇒ void
This method returns an undefined value.
Write an entry to cache.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/http/session/cache.rb', line 44 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 |