class ActiveSupport::Cache::SmartMemCache
Public Class Methods
new(*addresses, **args)
click to toggle source
known options:
ActiveSupport::Cache - universal options :namespace{nil}, :compress{true}, :compress_threshold{1k}, :expires_in{0}, :race_condition_ttl{0} ActiveSupport::Cache::Store :pool_size{5}, :pool_timeout{5} Dalli::Client :failover{true}, :serializer{Marshall}, :compressor{zlib}, :cache_nils{false} :namespace{nil}, :expires_in{0}, :compress{false} (separate from AS::C's same options above) :threadsafe{true} (using ConnPool turns this off automatically)
Calls superclass method
# File lib/active_support/cache/smart_mem_cache.rb, line 25 def initialize(*addresses, **args) args.reverse_merge!( namespace: ENV['MEMCACHE_NAMESPACE'], expires_in: 1.day, race_condition_ttl: 5.seconds, failover: true, pool_size: ENV.fetch('RAILS_MAX_THREADS'){ 5 }.to_i, ) addresses.push Array(args.delete(:url)) if addresses.empty? && args.key?(:url) super(*addresses, args) end
Public Instance Methods
decrement(name, amount = 1, options = nil)
click to toggle source
# File lib/active_support/cache/smart_mem_cache.rb, line 52 def decrement(name, amount = 1, options = nil) options = merged_options(options) instrument(:decrement, name, amount: amount) do rescue_error_with nil do @data.with { |c| c.decr(normalize_key(name, options), amount, options[:expires_in], 0) } end end end
increment(name, amount = 1, options = nil)
click to toggle source
MemCacheStore#increment docs say it will init any invalid value to 0. In reality, it will only increment a pre-existing, raw value. everything else returns nil or an error. This fixes init of missing value on both increment() and decrement(). Preexisting, invalid values still return errors.
# File lib/active_support/cache/smart_mem_cache.rb, line 43 def increment(name, amount = 1, options = nil) options = merged_options(options) instrument(:increment, name, amount: amount) do rescue_error_with nil do @data.with { |c| c.incr(normalize_key(name, options), amount, options[:expires_in], amount) } end end end