Class: HTTP::Session::Options::CacheOption

Inherits:
Object
  • Object
show all
Includes:
Optionable
Defined in:
lib/http/session/options/cache_option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Optionable

#enabled?, #initialize_options

Constructor Details

#initialize(opts) ⇒ CacheOption

Returns a new instance of CacheOption.

Parameters:

  • opts (Hash)

Options Hash (opts):

  • :private (Boolean)

    set true if it is a private cache

  • :shared (Boolean)

    set true if it is a shared cache

  • :store (ActiveSupport::Cache::Store)


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
# File 'lib/http/session/options/cache_option.rb', line 14

def initialize(opts)
  initialize_options(opts)

  # Shared Cache / Private Cache
  @shared =
    if @options.key?(:shared)
      raise ArgumentError, ":shared and :private cannot be used at the same time" if @options.key?(:private)
      !!@options[:shared]
    elsif @options.key?(:private)
      !@options[:private]
    else
      true
    end

  # Cache Store
  @store =
    if enabled?
      store = @options[:store]
      if store.respond_to?(:read) && store.respond_to?(:write)
        store
      else
        lookup_store(store)
      end
    end
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



8
9
10
# File 'lib/http/session/options/cache_option.rb', line 8

def store
  @store
end

Instance Method Details

#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.

Returns:

  • (Boolean)


52
53
54
# File 'lib/http/session/options/cache_option.rb', line 52

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

Returns:

  • (Boolean)


44
45
46
# File 'lib/http/session/options/cache_option.rb', line 44

def shared_cache?
  @shared
end