Class: ActiveSupport::Cache::TaggedStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::TaggedStore
- Defined in:
- lib/active_support/cache/tagged_store.rb
Defined Under Namespace
Classes: Dependencies
Instance Method Summary collapse
- #cleanup(options = nil) ⇒ Object
- #clear(options = nil) ⇒ Object
- #decrement(name, amount = 1, options = nil) ⇒ Object
- #delete_matched(matcher, options = nil) ⇒ Object
- #increment(name, amount = 1, options = nil) ⇒ Object
-
#initialize(options = nil) ⇒ TaggedStore
constructor
A new instance of TaggedStore.
- #read_tag(key) ⇒ Object
- #read_tags(*keys) ⇒ Object
- #tagged_fetch(name, options = nil) ⇒ Object
- #touch_tag(key) ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ TaggedStore
Returns a new instance of TaggedStore.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_support/cache/tagged_store.rb', line 37 def initialize( = nil) unless && [:tag_store] && [:entity_store] raise ":tag_store and :entity_store options are required" else @tag_store = Cache.lookup_store(*.delete(:tag_store)) @entity_store = Cache.lookup_store(*.delete(:entity_store)) @options = {} end end |
Instance Method Details
#cleanup(options = nil) ⇒ Object
130 131 132 |
# File 'lib/active_support/cache/tagged_store.rb', line 130 def cleanup( = nil) @entity_store.cleanup() end |
#clear(options = nil) ⇒ Object
134 135 136 |
# File 'lib/active_support/cache/tagged_store.rb', line 134 def clear( = nil) @entity_store.clear() end |
#decrement(name, amount = 1, options = nil) ⇒ Object
126 127 128 |
# File 'lib/active_support/cache/tagged_store.rb', line 126 def decrement(name, amount = 1, = nil) @entity_store.decrement(name, amount, ) end |
#delete_matched(matcher, options = nil) ⇒ Object
118 119 120 |
# File 'lib/active_support/cache/tagged_store.rb', line 118 def delete_matched(matcher, = nil) @entity_store.delete_matched(matcher, ) end |
#increment(name, amount = 1, options = nil) ⇒ Object
122 123 124 |
# File 'lib/active_support/cache/tagged_store.rb', line 122 def increment(name, amount = 1, = nil) @entity_store.increment(name, amount, ) end |
#read_tag(key) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/active_support/cache/tagged_store.rb', line 48 def read_tag(key) instrument(:read_tag, key) do key = (key) tag_value = @tag_store.read(key, :raw => true) if tag_value.nil? || tag_value.to_i.zero? new_value = Time.now.to_i @tag_store.write(key, new_value, :raw => true) new_value else tag_value.to_i end end end |
#read_tags(*keys) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/active_support/cache/tagged_store.rb', line 62 def (*keys) instrument(:read_tags, keys) do = keys. keys = keys.map { |k| (k) } = @tag_store.read_multi(*(keys + [.merge(:raw => true)])) (keys - .keys).each do |unknown_tag| [unknown_tag] = read_tag(unknown_tag) end end end |
#tagged_fetch(name, options = nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/active_support/cache/tagged_store.rb', line 81 def tagged_fetch(name, = nil) if block_given? = () key = namespaced_key(name, ) unless [:force] entry = instrument(:read, name, ) do |payload| payload[:super_operation] = :fetch if payload read_entry(key, ) end end if entry && entry.expired? race_ttl = [:race_condition_ttl].to_f if race_ttl and Time.now.to_f - entry.expires_at <= race_ttl entry.expires_at = Time.now + race_ttl write_entry(key, entry, :expires_in => race_ttl * 2) else delete_entry(key, ) end entry = nil end if entry instrument(:fetch_hit, name, ) { |payload| } entry.value else dependencies = Dependencies.new([:depends]) result = instrument(:generate, name, ) do |payload| yield(dependencies) end write(name, result, .merge(:depends => dependencies.)) result end else read(name, ) end end |
#touch_tag(key) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/active_support/cache/tagged_store.rb', line 74 def touch_tag(key) instrument(:touch_tag, key) do key = (key) @tag_store.increment(key) || @tag_store.write(key, Time.now.to_i, :raw => true) end end |