Class: AnyCache::Adapters::Dalli Private
- Defined in:
- lib/any_cache/adapters/dalli.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
- 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.
0
- 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.
nil
- 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
- MIN_DECRESEAD_VAL =
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
- 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
Instance Attribute Summary
Attributes inherited from Basic
Class Method Summary collapse
Instance Method Summary collapse
- #cleanup(**options) ⇒ void private
- #clear(**options) ⇒ void private
- #decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NilClass, Integer private
- #delete(key, **options) ⇒ void 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) ⇒ NilClass, Integer 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.
13 14 15 |
# File 'lib/any_cache/adapters/dalli.rb', line 13 def supported_driver?(driver) AnyCache::Drivers::Dalli.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.
243 244 245 |
# File 'lib/any_cache/adapters/dalli.rb', line 243 def cleanup(**) # NOTE: manual removing is not suppored (memcached doing it by itself) end |
#clear(**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.
234 235 236 |
# File 'lib/any_cache/adapters/dalli.rb', line 234 def clear(**) flush(0) # NOTE: 0 is a flush delay end |
#decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NilClass, Integer
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.
199 200 201 202 203 204 205 206 |
# File 'lib/any_cache/adapters/dalli.rb', line 199 def decrement(key, amount = DEFAULT_INCR_DECR_AMOUNT, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) # TODO: think about #cas and Concurrent::ReentrantReadWriteLock decr(key, amount, expires_in, MIN_DECRESEAD_VAL).tap do |new_amount| touch(key, expires_in) if new_amount && expires_in.positive? end end |
#delete(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.
162 163 164 |
# File 'lib/any_cache/adapters/dalli.rb', line 162 def delete(key, **) driver.delete(key) 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.
172 173 174 |
# File 'lib/any_cache/adapters/dalli.rb', line 172 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.
253 254 255 |
# File 'lib/any_cache/adapters/dalli.rb', line 253 def exist?(key, **) !get(key).nil? # NOTE: can conflict with :cache_nils Dalli::Client's config 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.
214 215 216 217 |
# File 'lib/any_cache/adapters/dalli.rb', line 214 def expire(key, expires_in: DEAD_TTL) is_alive = expires_in ? expires_in.positive? : false is_alive ? touch(key, expires_in) : driver.delete(key) 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.
131 132 133 134 135 136 137 138 139 |
# File 'lib/any_cache/adapters/dalli.rb', line 131 def fetch(key, **, &fallback) force_rewrite = .fetch(:force, false) force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call) # NOTE: can conflict with :cache_nils Dalli::Client's config read(key, **).tap { |value| return value if value } unless force_rewrite yield(key).tap { |value| write(key, value, **) } if block_given? 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.
149 150 151 152 153 154 |
# File 'lib/any_cache/adapters/dalli.rb', line 149 def fetch_multi(*keys, **, &fallback) # TODO: think about multi-thread approach keys.each_with_object({}) do |key, dataset| dataset[key] = fetch(key, **, &fallback) end end |
#increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **options) ⇒ NilClass, Integer
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.
183 184 185 186 187 188 189 190 |
# File 'lib/any_cache/adapters/dalli.rb', line 183 def increment(key, amount = DEFAULT_INCR_DECR_AMOUNT, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) # TODO: think about #cas and Concurrent::ReentrantReadWriteLock incr(key, amount, expires_in, amount).tap do |new_amount| touch(key, expires_in) if new_amount && expires_in.positive? 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.
225 226 227 |
# File 'lib/any_cache/adapters/dalli.rb', line 225 def persist(key, **) touch(key, NO_EXPIRATION_TTL) 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.
65 66 67 68 69 70 |
# File 'lib/any_cache/adapters/dalli.rb', line 65 def read(key, **) raw = .fetch(:raw, false) value = get(key) raw ? value : detransform_value(value) 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.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/any_cache/adapters/dalli.rb', line 78 def read_multi(*keys, **) raw = .fetch(:raw, false) entries = get_multi(*keys).tap do |res| # NOTE: # dalli does not return nonexistent entries # but we want to be consistent with another cache storages # that returns nonexistent antries as { key => nil } pair res.merge!(Hash[(keys.map(&:to_s) - res.keys).zip(READ_MULTI_EMPTY_KEYS_SET)]) # NOTE: # dalli stringifies requred keys but we want to be consistent with symbol keys # cuz another cache storages are already consistent keys.each { |key| res.key?(key) ? next : (res[key] = res.delete(key.to_s)) } end raw ? entries : detransform_pairset(entries) 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.
105 106 107 108 109 110 111 |
# File 'lib/any_cache/adapters/dalli.rb', line 105 def write(key, value, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) raw = .fetch(:raw, false) value = transform_value(value) unless raw set(key, value, 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.
119 120 121 |
# File 'lib/any_cache/adapters/dalli.rb', line 119 def write_multi(entries, **) entries.each_pair { |key, value| write(key, value, **) } end |