Class: HTTP::Session::Cache

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options) ⇒ Cache

Returns a new instance of Cache.

Parameters:



22
23
24
25
# File 'lib/http/session/cache.rb', line 22

def initialize(options)
  super()
  @options = options
end

Instance Method Details

#enabled?Boolean

True when it is enabled.

Returns:

  • (Boolean)


9
# File 'lib/http/session/cache.rb', line 9

def_delegator :@options, :enabled?

#private_cache?Boolean

True when it is a private cache.

Returns:

  • (Boolean)


19
# File 'lib/http/session/cache.rb', line 19

def_delegator :@options, :private_cache?

#read(req) ⇒ nil, Entry

Read an entry from cache.

Parameters:

Returns:



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.

Returns:

  • (Boolean)


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.

Parameters:



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