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.



45
46
# File 'lib/active_support/cache.rb', line 45

def initialize
end

Instance Method Details

#decrement(key, amount = 1) ⇒ Object



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

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



86
87
88
# File 'lib/active_support/cache.rb', line 86

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

#delete_matched(matcher, options = nil) ⇒ Object



90
91
92
# File 'lib/active_support/cache.rb', line 90

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

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

Returns:

  • (Boolean)


94
95
96
# File 'lib/active_support/cache.rb', line 94

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

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

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



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

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



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

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



78
79
80
# File 'lib/active_support/cache.rb', line 78

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

#threadsafe!Object



48
49
50
51
52
# File 'lib/active_support/cache.rb', line 48

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

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



82
83
84
# File 'lib/active_support/cache.rb', line 82

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