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
- #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
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
#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.
218 219 220 |
# File 'lib/any_cache/adapters/dalli.rb', line 218 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.
183 184 185 186 187 188 189 190 |
# File 'lib/any_cache/adapters/dalli.rb', line 183 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.
146 147 148 |
# File 'lib/any_cache/adapters/dalli.rb', line 146 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.
156 157 158 |
# File 'lib/any_cache/adapters/dalli.rb', line 156 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.
228 229 230 |
# File 'lib/any_cache/adapters/dalli.rb', line 228 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.
198 199 200 201 |
# File 'lib/any_cache/adapters/dalli.rb', line 198 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.
115 116 117 118 119 120 121 122 123 |
# File 'lib/any_cache/adapters/dalli.rb', line 115 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.
133 134 135 136 137 138 |
# File 'lib/any_cache/adapters/dalli.rb', line 133 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.
167 168 169 170 171 172 173 174 |
# File 'lib/any_cache/adapters/dalli.rb', line 167 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.
209 210 211 |
# File 'lib/any_cache/adapters/dalli.rb', line 209 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 |
# File 'lib/any_cache/adapters/dalli.rb', line 65 def read(key, **) get(key) 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.
75 76 77 78 79 |
# File 'lib/any_cache/adapters/dalli.rb', line 75 def read_multi(*keys, **) get_multi(*keys).tap do |res| res.merge!(Hash[(keys - res.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.
88 89 90 91 92 93 |
# File 'lib/any_cache/adapters/dalli.rb', line 88 def write(key, value, **) expires_in = .fetch(:expires_in, NO_EXPIRATION_TTL) raw = .fetch(:raw, true) 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.
101 102 103 104 105 |
# File 'lib/any_cache/adapters/dalli.rb', line 101 def write_multi(entries, **) raw = .fetch(:raw, true) entries.each_pair { |key, value| write(key, value, raw: raw) } end |