Class: AnyCache::Adapters::ActiveSupportNaiveStore Private
- Defined in:
- lib/any_cache/adapters/active_support_naive_store.rb,
lib/any_cache/adapters/active_support_naive_store/expire.rb,
lib/any_cache/adapters/active_support_naive_store/persist.rb,
lib/any_cache/adapters/active_support_naive_store/decrement.rb,
lib/any_cache/adapters/active_support_naive_store/increment.rb,
lib/any_cache/adapters/active_support_naive_store/operation.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.
Direct Known Subclasses
Defined Under Namespace
Classes: Decrement, Expire, Increment, Operation, Persist
Instance Attribute Summary
Attributes inherited from Basic
Instance Method Summary collapse
- #cleanup(**options) ⇒ void private
- #clear(**options) ⇒ void private
- #decrement(key, amount = self.class::Decrement::DEFAULT_AMOUNT, **options) ⇒ Integer, Float private
- #delete(key, **options) ⇒ void private
- #delete_matched(pattern, **options) ⇒ void private
- #exist?(key, **options) ⇒ Boolean private
- #expire(key, expires_in: self.class::Operation::DEAD_TTL) ⇒ void private
- #fetch(key, **options, &fallback) ⇒ Object private
- #fetch_multi(*keys, **options, &fallback) ⇒ Hash private
- #increment(key, amount = self.class::Increment::DEFAULT_AMOUNT, **options) ⇒ Integer, Float private
- #initialize(driver) ⇒ void constructor 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 Delegator
Methods inherited from Basic
Methods included from Dumper::InterfaceAccessMixin
#detransform_pairset, #detransform_value, #transform_pairset, #transform_value
Constructor Details
#initialize(driver) ⇒ 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.
18 19 20 21 22 23 24 25 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 18 def initialize(driver) super @lock = Concurrent::ReentrantReadWriteLock.new @incr_operation = self.class::Increment.new(driver) @decr_operation = self.class::Decrement.new(driver) @expr_operation = self.class::Expire.new(driver) @pers_operation = self.class::Persist.new(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.
85 86 87 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 85 def cleanup(**) lock.with_write_lock { super } 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.
76 77 78 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 76 def clear(**) lock.with_write_lock { super } end |
#decrement(key, amount = self.class::Decrement::DEFAULT_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.
181 182 183 184 185 186 187 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 181 def decrement(key, amount = self.class::Decrement::DEFAULT_AMOUNT, **) lock.with_write_lock do expires_in = .fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) decr_operation.call(key, amount, expires_in: expires_in) 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.
57 58 59 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 57 def delete(key, **) lock.with_write_lock { super } 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.
67 68 69 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 67 def delete_matched(pattern, **) lock.with_write_lock { super } 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_naive_store.rb', line 215 def exist?(key, **) lock.with_read_lock { super } end |
#expire(key, expires_in: self.class::Operation::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 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 195 def expire(key, expires_in: self.class::Operation::DEAD_TTL) lock.with_write_lock { expr_operation.call(key, expires_in: expires_in) } 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.
126 127 128 129 130 131 132 133 134 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 126 def fetch(key, **, &fallback) lock.with_write_lock do force_rewrite = .fetch(:force, false) force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call) expires_in = .fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) super(key, force: force_rewrite, expires_in: expires_in, &fallback) end 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.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 144 def fetch_multi(*keys, **, &fallback) lock.with_write_lock do force_rewrite = .fetch(:force, false) expires_in = .fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) # NOTE: # use own #fetch_multi implementation cuz original #fetch_multi # does not support :force option keys.each_with_object({}) do |key, dataset| force = force_rewrite.respond_to?(:call) ? force_rewrite.call(key) : force_rewrite dataset[key] = driver.fetch(key, force: force, expires_in: expires_in, &fallback) end end end |
#increment(key, amount = self.class::Increment::DEFAULT_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.
166 167 168 169 170 171 172 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 166 def increment(key, amount = self.class::Increment::DEFAULT_AMOUNT, **) lock.with_write_lock do expires_in = .fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) incr_operation.call(key, amount, expires_in: expires_in) 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_naive_store.rb', line 205 def persist(key, **) lock.with_write_lock { pers_operation.call(key) } 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.
33 34 35 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 33 def read(key, **) lock.with_read_lock { super } 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.
43 44 45 46 47 48 49 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 43 def read_multi(*keys, **) lock.with_read_lock do super.tap do |res| res.merge!(Hash[(keys - res.keys).zip(Operation::READ_MULTI_EMPTY_KEYS_SET)]) end 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.
96 97 98 99 100 101 102 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 96 def write(key, value, **) lock.with_write_lock do expires_in = .fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) super(key, value, expires_in: expires_in) end 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.
110 111 112 113 114 115 116 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 110 def write_multi(entries, **) lock.with_write_lock do expires_in = self.class::Operation::NO_EXPIRATION_TTL super(entries, expires_in: expires_in) end end |