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
- #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
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
#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.
172 173 174 175 176 177 178 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 172 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.
206 207 208 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 206 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.
186 187 188 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 186 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.
117 118 119 120 121 122 123 124 125 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 117 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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 135 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.
157 158 159 160 161 162 163 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 157 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.
196 197 198 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 196 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.
87 88 89 90 91 92 93 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 87 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.
101 102 103 104 105 106 107 |
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 101 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 |