Class: AnyCache::Adapters::ActiveSupportDalliStore Private
- Defined in:
- lib/any_cache/adapters/active_support_dalli_store.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- READ_MULTI_EMPTY_KEYS_SET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
[].freeze
- DEFAULT_INCR_DECR_AMOUNT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1- INITIAL_DECREMNETED_VALUE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
0- NO_EXPIRATION_TTL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
nil- DEAD_TTL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
0
Instance Attribute Summary
Attributes inherited from Basic
Class Method Summary collapse
Instance Method Summary collapse
- #decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ Integer, Float private
- #delete_matched(pattern, **options) ⇒ void private
- #exist?(key, **options) ⇒ BOolean private
- #expire(key, expires_in: DEAD_TTL) ⇒ void private
- #fetch(key, **options, &fallback) ⇒ Object private
- #fetch_multi(*keys, **options, &fallback) ⇒ Hash private
- #increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ Integer, Float private
- #persist(key, **options) ⇒ void private
- #read(key, **options) ⇒ void private
- #read_multi(*keys, **options) ⇒ Hash private
- #write(key, value, **options) ⇒ void private
- #write_multi(entries, **options) ⇒ void private
Methods inherited from Basic
Constructor Details
This class inherits a constructor from AnyCache::Adapters::Basic
Class Method Details
.supported_driver?(driver) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 13 def supported_driver?(driver) AnyCache::Drivers::ActiveSupportDalliStore.supported_source?(driver) end |
Instance Method Details
#decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ Integer, Float
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 160 def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) unless exist?(key) # NOTE: Dalli::Client (under the hood of this) can't decrement: # - non-raw values; # - values lower than zero; # - empty entries; write(key, INITIAL_DECREMNETED_VALUE, expires_in: expires_in) && INITIAL_DECREMNETED_VALUE else driver.decrement(key, amount).tap do expire(key, expires_in: expires_in) if expires_in end end end |
#delete_matched(pattern, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
182 183 184 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 182 def delete_matched(pattern, **) # TODO: make it real >:] end |
#exist?(key, **options) ⇒ BOolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
215 216 217 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 215 def exist?(key, **) driver.exist?(key, ) end |
#expire(key, expires_in: DEAD_TTL) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
192 193 194 195 196 197 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 192 def expire(key, expires_in: DEAD_TTL) read(key).tap do |value| is_alive = expires_in ? expires_in.positive? : false is_alive ? write(key, value, expires_in: expires_in) : delete(key) end end |
#fetch(key, **options, &fallback) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
113 114 115 116 117 118 119 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 113 def fetch(key, **, &fallback) force_rewrite = .fetch(:force, false) force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) driver.fetch(key, force: force_rewrite, expires_in: expires_in, &fallback) end |
#fetch_multi(*keys, **options, &fallback) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
128 129 130 131 132 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 128 def fetch_multi(*keys, **, &fallback) keys.each_with_object({}) do |key, dataset| dataset[key] = fetch(key, **, &fallback) end end |
#increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ Integer, Float
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 141 def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) unless exist?(key) write(key, amount, expires_in: expires_in) && amount else driver.increment(key, amount).tap do expire(key, expires_in: expires_in) if expires_in end end end |
#persist(key, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
205 206 207 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 205 def persist(key, **) read(key).tap { |value| write(key, value) } end |
#read(key, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
57 58 59 60 61 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 57 def read(key, **) raw = .fetch(:raw, true) driver.read(key, raw: raw) end |
#read_multi(*keys, **options) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 72 73 74 75 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 69 def read_multi(*keys, **) raw = .fetch(:raw, true) driver.read_multi(*keys, raw: raw).tap do |entries| entries.merge!(Hash[(keys - entries.keys).zip(READ_MULTI_EMPTY_KEYS_SET)]) end end |
#write(key, value, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
84 85 86 87 88 89 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 84 def write(key, value, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) raw = .fetch(:raw, true) driver.write(key, value, expires_in: expires_in, raw: raw) end |
#write_multi(entries, **options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
97 98 99 100 101 102 103 104 |
# File 'lib/any_cache/adapters/active_support_dalli_store.rb', line 97 def write_multi(entries, **) raw = .fetch(:raw, true) # NOTE: ActiveSupport::Cache::DalliStore does not support #write_multi : entries.each_pair do |key, value| write(key, value, expires_in: NO_EXPIRATION_TTL, raw: raw) end end |