Class: ActiveSupport::Cache::MonetaStore
- Inherits:
-
Store
- Object
- Store
- ActiveSupport::Cache::MonetaStore
- Includes:
- Rails5Support
- Defined in:
- lib/active_support/cache/moneta_store.rb
Defined Under Namespace
Modules: Rails5Support
Instance Method Summary collapse
- #clear(options = nil) ⇒ Object
- #decrement(key, amount = 1, options = nil) ⇒ Object
-
#exist?(name, options = {}) ⇒ Boolean
This prevents underlying Moneta transformers from erroring on raw values.
- #fetch_multi(*names) ⇒ Object
- #increment(key, amount = 1, options = nil) ⇒ Object
-
#initialize(options = nil) ⇒ MonetaStore
constructor
A new instance of MonetaStore.
- #read_multi(*names) ⇒ Object
- #write_multi(hash, options = nil) ⇒ Object
Constructor Details
#initialize(options = nil) ⇒ MonetaStore
Returns a new instance of MonetaStore.
5 6 7 8 9 10 |
# File 'lib/active_support/cache/moneta_store.rb', line 5 def initialize( = nil) raise ArgumentError, 'Option :store is required' unless @store = .delete(:store) @store = ::Moneta.new(@store, expires: true) if Symbol === @store super() extend Strategy::LocalCache end |
Instance Method Details
#clear(options = nil) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/active_support/cache/moneta_store.rb', line 26 def clear( = nil) = () instrument(:clear, nil, nil) do @store.clear(()) end end |
#decrement(key, amount = 1, options = nil) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/active_support/cache/moneta_store.rb', line 19 def decrement(key, amount = 1, = nil) = () instrument(:decrement, key, amount: amount) do @store.increment(normalize_key(key, ), -amount, ()) end end |
#exist?(name, options = {}) ⇒ Boolean
This prevents underlying Moneta transformers from erroring on raw values
34 35 36 37 38 |
# File 'lib/active_support/cache/moneta_store.rb', line 34 def exist?(name, = {}) super rescue super(name, .merge(raw: true)) end |
#fetch_multi(*names) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_support/cache/moneta_store.rb', line 45 def fetch_multi(*names) raise ArgumentError, "Missing block: `Cache#fetch_multi` requires a block." \ unless block_given? = names. = () instrument :read_multi, names, do |payload| read_multi_entries(names, ).tap do |results| payload[:hits] = results.keys payload[:super_operation] = :fetch_multi writes = {} (names - results.keys).each do |name| results[name] = writes[name] = yield(name) end write_multi writes, end end end |
#increment(key, amount = 1, options = nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/active_support/cache/moneta_store.rb', line 12 def increment(key, amount = 1, = nil) = () instrument(:increment, key, amount: amount) do @store.increment(normalize_key(key, ), amount, ()) end end |
#read_multi(*names) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_support/cache/moneta_store.rb', line 68 def read_multi(*names) = names. = () instrument :read_multi, names, do |payload| read_multi_entries(names, ).tap do |results| payload[:hits] = results.keys end end end |
#write_multi(hash, options = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/active_support/cache/moneta_store.rb', line 79 def write_multi(hash, = nil) = () instrument :write_multi, hash, do entries = hash.each_with_object({}) do |(name, value), memo| memo[normalize_key(name, )] = \ Entry.new(value, .merge(version: normalize_version(name, ))) end write_multi_entries entries, end end |