class Alephant::Sequencer::SequenceCache
Constants
- DEFAULT_TTL
Attributes
config[R]
Public Class Methods
new(config = {})
click to toggle source
# File lib/alephant/sequencer/sequence_cache.rb, line 13 def initialize(config = {}) @config = config if config_endpoint.nil? logger.debug 'Alephant::SequenceCache::#initialize: No config endpoint, NullClient used' logger.metric 'NoConfigEndpoint' @client = NullClient.new else @client ||= ::Dalli::Client.new(config_endpoint, expires_in: ttl) end end
Public Instance Methods
get(key) { || ... }
click to toggle source
# File lib/alephant/sequencer/sequence_cache.rb, line 25 def get(key) versioned_key = versioned key result = @client.get versioned_key logger.info "Alephant::SequenceCache#get key: #{versioned_key} - #{result ? 'hit' : 'miss'}" logger.metric 'GetKeyMiss' unless result result ? result : set(key, yield) rescue StandardError => e yield end
set(key, value, ttl = nil)
click to toggle source
# File lib/alephant/sequencer/sequence_cache.rb, line 35 def set(key, value, ttl = nil) value.tap { |o| @client.set(versioned(key), o, ttl) } end
Private Instance Methods
cache_version()
click to toggle source
# File lib/alephant/sequencer/sequence_cache.rb, line 53 def cache_version config[:elasticache_cache_version] || config['elasticache_cache_version'] end
config_endpoint()
click to toggle source
# File lib/alephant/sequencer/sequence_cache.rb, line 41 def config_endpoint config[:elasticache_config_endpoint] || config['elasticache_config_endpoint'] end
ttl()
click to toggle source
# File lib/alephant/sequencer/sequence_cache.rb, line 45 def ttl config[:sequencer_elasticache_ttl] || config['sequencer_elasticache_ttl'] || DEFAULT_TTL end
versioned(key)
click to toggle source
# File lib/alephant/sequencer/sequence_cache.rb, line 49 def versioned(key) [key, cache_version].compact.join('_') end