Class: AnyCache::Adapters::ActiveSupportMemCacheStore Private
- Defined in:
- lib/any_cache/adapters/active_support_mem_cache_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
- 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
- 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
Instance Attribute Summary
Attributes inherited from Basic
Class Method Summary collapse
Instance Method Summary collapse
- #cleanup(**options) ⇒ void private
- #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) ⇒ Object private
- #read_multi(*keys, **options) ⇒ Hash private
- #write(key, value, **options) ⇒ void private
- #write_multi(entries, **options) ⇒ void private
Methods inherited from Basic
Methods included from Dumper::InterfaceAccessMixin
#detransform_pairset, #detransform_value, #transform_pairset, #transform_value
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.
15 16 17 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 15 def supported_driver?(driver) AnyCache::Drivers::ActiveSupportMemCacheStore.supported_source?(driver) end |
Instance Method Details
#cleanup(**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.
227 228 229 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 227 def cleanup(**) # NOTE: manual removing is not supported (memcached doing this by itself) end |
#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.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 172 def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) unless exist?(key) # NOTE: Dalli::Client can't decrement: # - non-raw values; # - values lower than zero; # - empty entries; write(key, INITIAL_DECREMNETED_VALUE, expires_in: expires_in, raw: true) 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.
142 143 144 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 142 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.
218 219 220 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 218 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.
195 196 197 198 199 200 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 195 def expire(key, expires_in: DEAD_TTL) read(key, raw: true).tap do |value| is_alive = expires_in ? expires_in.positive? : false is_alive ? write(key, value, expires_in: expires_in, raw: true) : 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.
114 115 116 117 118 119 120 121 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 114 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) raw = .fetch(:raw, false) driver.fetch(key, force: force_rewrite, expires_in: expires_in, raw: raw, &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.
130 131 132 133 134 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 130 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.
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 153 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, raw: true) && 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.
208 209 210 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 208 def persist(key, **) read(key).tap { |value| write(key, value) } end |
#read(key, **options) ⇒ 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.
59 60 61 62 63 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 59 def read(key, **) raw = .fetch(:raw, false) 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.
71 72 73 74 75 76 77 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 71 def read_multi(*keys, **) raw = .fetch(:raw, false) 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.
87 88 89 90 91 92 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 87 def write(key, value, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) raw = .fetch(:raw, false) 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.
100 101 102 103 104 |
# File 'lib/any_cache/adapters/active_support_mem_cache_store.rb', line 100 def write_multi(entries, **) raw = .fetch(:raw, false) driver.write_multi(entries, expires_in: NO_EXPIRATION_TTL, raw: raw) end |