Class: ActiveSupport::Cache::Store
- Defined in:
- lib/active_support/cache.rb
Direct Known Subclasses
Instance Method Summary collapse
- #decrement(key, amount = 1) ⇒ Object
- #delete(key, options = nil) ⇒ Object
- #delete_matched(matcher, options = nil) ⇒ Object
- #exist?(key, options = nil) ⇒ Boolean
-
#fetch(key, options = {}) ⇒ Object
Pass
:force => true
to force a cache miss. - #increment(key, amount = 1) ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #read(key, options = nil) ⇒ Object
- #threadsafe! ⇒ Object
- #write(key, value, options = nil) ⇒ Object
Constructor Details
#initialize ⇒ Store
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, = nil) log("delete", key, ) end |
#delete_matched(matcher, options = nil) ⇒ Object
90 91 92 |
# File 'lib/active_support/cache.rb', line 90 def delete_matched(matcher, = nil) log("delete matched", matcher.inspect, ) end |
#exist?(key, options = nil) ⇒ Boolean
94 95 96 |
# File 'lib/active_support/cache.rb', line 94 def exist?(key, = nil) log("exist?", key, ) 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, = {}) @logger_off = true if ![:force] && value = read(key, ) @logger_off = false log("hit", key, ) value elsif block_given? @logger_off = false log("miss", key, ) value = nil seconds = Benchmark.realtime { value = yield } @logger_off = true write(key, value, ) @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, = nil) log("read", key, ) 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, = nil) log("write", key, ) end |