class AnyCache::Adapters::ActiveSupportNaiveStore::Decrement

@api private @since 0.1.0

Constants

DEFAULT_AMOUNT

@return [Integer]

@api private @since 0.1.0

Public Instance Methods

call(key, amount = DEFAULT_AMOUNT, expires_in: NO_EXPIRATION_TTL) click to toggle source

@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/decrement.rb, line 23
def call(key, amount = DEFAULT_AMOUNT, expires_in: NO_EXPIRATION_TTL)
  expires_in ? decr_and_expire(key, amount, expires_in) : decr_existing(key, amount)
end

Private Instance Methods

decr_and_expire(key, amount, expires_in) click to toggle source

@param key [String] @param amount [Integer, Float] @param expires_in [NilClass, Integer] @return [Integer, Float]

@api private @since 0.1.0

# File lib/any_cache/adapters/active_support_naive_store/decrement.rb, line 36
def decr_and_expire(key, amount, expires_in)
  new_amount = decrement(key, amount, expires_in: expires_in)
  new_amount || decr_non_existing(key, amount, expires_in)
end
decr_existing(key, amount) click to toggle source

@param key [String] @param amount [Integer, Float] @return [Integer, Float]

@api private @since 0.1.0

# File lib/any_cache/adapters/active_support_naive_store/decrement.rb, line 47
def decr_existing(key, amount)
  new_amount = begin
    entry = fetch_entry(key)
    decrement(key, amount, expires_in: calc_entry_expiration(entry)) if entry
  end

  new_amount || decr_non_existing(key, amount)
end
decr_non_existing(key, amount, expires_in = NO_EXPIRATION_TTL) click to toggle source

@param key [String] @param amount [Integer, Float] @param expires_in [NilClass, Integer] @return [Integer, Float]

@api private @since 0.1.0

# File lib/any_cache/adapters/active_support_naive_store/decrement.rb, line 63
def decr_non_existing(key, amount, expires_in = NO_EXPIRATION_TTL)
  amount = -amount
  (expires_in ? write(key, amount, expires_in: expires_in) : write(key, amount)) && amount
end