class AnyCache::Adapters::ActiveSupportNaiveStore
@api private @since 0.1.0
Attributes
@return [Operation::Decrement]
@api private @since 0.1.0
@return [Operation::Expire]
@api private @since 0.1.0
@return [Operation::Increment]
@api private @since 0.1.0
@return [Concurrent::ReentrantReadWriteLock]
@api private @since 0.1.0
@return [Operation::Persist]
@api private @since 0.1.0
Public Class Methods
@param driver [Object] @return [void]
@api private @since 0.1.0
# 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
Public Instance Methods
@param options [Hash] @return [void]
@api private @since 0.4.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 85 def cleanup(**options) lock.with_write_lock { super } end
@param options [Hash] @return [void]
@api private @since 0.1.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 76 def clear(**options) lock.with_write_lock { super } end
@param key [String] @param amount [Integer, Float] @option expires_in [NilClass, Integer] @return [Integer, Float]
@api private @since 0.1.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 181 def decrement(key, amount = self.class::Decrement::DEFAULT_AMOUNT, **options) lock.with_write_lock do expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) decr_operation.call(key, amount, expires_in: expires_in) end end
@param key [String] @param options [Hash] @return [void]
@api private @since 0.1.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 57 def delete(key, **options) lock.with_write_lock { super } end
@param pattern [String, Regexp] @param options [Hash] @return [void]
@api private @since 0.3.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 67 def delete_matched(pattern, **options) lock.with_write_lock { super } end
@param key [String] @param options [Hash] @return [Boolean]
@api private @since 0.2.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 215 def exist?(key, **options) lock.with_read_lock { super } end
@param key [String] @option expires_in [NilClass, Integer] @return [void]
@api private @since 0.1.0
# 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
@param key [String] @param fallback [Proc] @option expires_in [Integer] @option force [Boolean, Proc] @return [Object]
@api private @since 0.2.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 126 def fetch(key, **options, &fallback) lock.with_write_lock do force_rewrite = options.fetch(:force, false) force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call) expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) super(key, force: force_rewrite, expires_in: expires_in, &fallback) end end
@param keys [Array<String>] @param fallback [Proc] @option force [Boolean, Proc] @option expires_in [Integer] @return [Hash]
@api private @since 0.3.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 144 def fetch_multi(*keys, **options, &fallback) lock.with_write_lock do force_rewrite = options.fetch(:force, false) expires_in = options.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
@param key [String] @param amount [Integer, Float] @option expires_in [NilClass, Integer] @return [Integer, Float]
@api private @since 0.1.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 166 def increment(key, amount = self.class::Increment::DEFAULT_AMOUNT, **options) lock.with_write_lock do expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) incr_operation.call(key, amount, expires_in: expires_in) end end
@param key [String] @param options [Hash] @return [void]
@api private @since 0.1.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 205 def persist(key, **options) lock.with_write_lock { pers_operation.call(key) } end
@param key [String] @param options [Hash] @return [Object]
@api private @since 0.1.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 33 def read(key, **options) lock.with_read_lock { super } end
@param keys [Array<String>] @param options [Hash] @return [Hash]
@api private @since 0.3.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 43 def read_multi(*keys, **options) 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
@param key [String] @param value [Object] @param options [Hash] @return [void]
@api private @since 0.1.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 96 def write(key, value, **options) lock.with_write_lock do expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL) super(key, value, expires_in: expires_in) end end
@param entries [Hash] @param options [Hash] @return [void]
@api private @since 0.3.0
# File lib/any_cache/adapters/active_support_naive_store.rb, line 110 def write_multi(entries, **options) lock.with_write_lock do expires_in = self.class::Operation::NO_EXPIRATION_TTL super(entries, expires_in: expires_in) end end