Class: HTTP::Session::Options::CacheOption
- Inherits:
-
Object
- Object
- HTTP::Session::Options::CacheOption
- Defined in:
- lib/http/session/options/cache_option.rb
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Indicates whether or not the session cache feature is enabled.
-
#initialize(options) ⇒ CacheOption
constructor
A new instance of CacheOption.
-
#private_cache? ⇒ Boolean
True when it is a private cache.
-
#shared_cache? ⇒ Boolean
True when it is a shared cache.
Constructor Details
#initialize(options) ⇒ CacheOption
Returns a new instance of CacheOption.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/http/session/options/cache_option.rb', line 12 def initialize() = case when nil, false then {enabled: false} when true then {enabled: true} else end # Enabled / Disabled @enabled = .fetch(:enabled, true) # Shared Cache / Private Cache @shared = if .key?(:shared) raise ArgumentError, ":shared and :private cannot be used at the same time" if .key?(:private) !![:shared] elsif .key?(:private) ![:private] else true end # Cache Store @store = if @enabled store = [:store] if store.respond_to?(:read) && store.respond_to?(:write) store else lookup_store(store) end end end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
6 7 8 |
# File 'lib/http/session/options/cache_option.rb', line 6 def store @store end |
Instance Method Details
#enabled? ⇒ Boolean
Indicates whether or not the session cache feature is enabled.
47 48 49 |
# File 'lib/http/session/options/cache_option.rb', line 47 def enabled? @enabled end |
#private_cache? ⇒ Boolean
True when it is a private cache.
Private Cache that exists in the client. It is also called local cache or browser cache. It can store and reuse personalized content for a single user.
63 64 65 |
# File 'lib/http/session/options/cache_option.rb', line 63 def private_cache? !shared_cache? end |
#shared_cache? ⇒ Boolean
True when it is a shared cache.
Shared Cache that exists between the origin server and clients (e.g. Proxy, CDN). It stores a single response and reuses it with multiple users
55 56 57 |
# File 'lib/http/session/options/cache_option.rb', line 55 def shared_cache? @shared end |