Class: HTTP::Session::Cache

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



6
7
8
9
10
# File 'lib/http/session/cache.rb', line 6

def initialize(options)
  super()

  @options = options
end

Instance Method Details

#private?Boolean

True when it is a private cache.

Returns:

  • (Boolean)


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.

Parameters:

Returns:



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.

Returns:

  • (Boolean)


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.

Parameters:



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