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.
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, = nil) log("delete", key, ) end |
#delete_matched(matcher, options = nil) ⇒ Object
88 89 90 |
# File 'lib/active_support/cache.rb', line 88 def delete_matched(matcher, = nil) log("delete matched", matcher.inspect, ) end |
#exist?(key, options = nil) ⇒ Boolean
92 93 94 |
# File 'lib/active_support/cache.rb', line 92 def exist?(key, = nil) log("exist?", key, ) 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, = {}) @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
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, = nil) log("read", key, ) 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, = nil) log("write", key, ) end |