Class: ActiveSupport::Cache::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/cache.rb

Direct Known Subclasses

FileStore, MemCacheStore, MemoryStore

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.


43
44
# File 'lib/active_support/cache.rb', line 43

def initialize
end

Instance Method Details

#decrement(key, amount = 1) ⇒ Object


105
106
107
108
109
110
111
112
# File 'lib/active_support/cache.rb', line 105

def decrement(key, amount = 1)
  log("decrementing", key, amount)
  if num = read(key)
    write(key, num - amount)
  else
    nil
  end
end

#delete(key, options = nil) ⇒ Object


84
85
86
# File 'lib/active_support/cache.rb', line 84

def delete(key, options = nil)
  log("delete", key, options)
end

#delete_matched(matcher, options = nil) ⇒ Object


88
89
90
# File 'lib/active_support/cache.rb', line 88

def delete_matched(matcher, options = nil)
  log("delete matched", matcher.inspect, options)
end

#exist?(key, options = nil) ⇒ Boolean

Returns:

  • (Boolean)

92
93
94
# File 'lib/active_support/cache.rb', line 92

def exist?(key, options = nil)
  log("exist?", key, options)
end

#fetch(key, options = {}) ⇒ Object

Pass :force => true to force a cache miss.


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_support/cache.rb', line 53

def fetch(key, options = {})
  @logger_off = true
  if !options[:force] && value = read(key, options)
    @logger_off = false
    log("hit", key, options)
    value
  elsif block_given?
    @logger_off = false
    log("miss", key, options)

    value = nil
    seconds = Benchmark.realtime { value = yield }

    @logger_off = true
    write(key, value, options)
    @logger_off = false

    log("write (will save #{'%.5f' % seconds})", key, nil)

    value
  end
end

#increment(key, amount = 1) ⇒ Object


96
97
98
99
100
101
102
103
# File 'lib/active_support/cache.rb', line 96

def increment(key, amount = 1)
  log("incrementing", key, amount)
  if num = read(key)
    write(key, num + amount)
  else
    nil
  end
end

#read(key, options = nil) ⇒ Object


76
77
78
# File 'lib/active_support/cache.rb', line 76

def read(key, options = nil)
  log("read", key, options)
end

#threadsafe!Object


46
47
48
49
50
# File 'lib/active_support/cache.rb', line 46

def threadsafe!
  @mutex = Mutex.new
  self.class.send :include, ThreadSafety
  self
end

#write(key, value, options = nil) ⇒ Object


80
81
82
# File 'lib/active_support/cache.rb', line 80

def write(key, value, options = nil)
  log("write", key, options)
end