class Cachext::Client
Public Class Methods
new(config)
click to toggle source
# File lib/cachext/client.rb, line 11 def initialize config @config = config end
Public Instance Methods
fetch(key, options_hash = {})
click to toggle source
# File lib/cachext/client.rb, line 15 def fetch key, options_hash = {}, &block options = Options.new @config, options_hash retval = read key, options return retval unless retval.nil? call_block key, options, &block rescue *Array(options.not_found_error) => e handle_not_found key, options, e rescue Features::Lock::TimeoutWaitingForLock, *options.errors => e handle_error key, options, e end
Private Instance Methods
call_block(key, options, &block)
click to toggle source
# File lib/cachext/client.rb, line 31 def call_block key, options, &block fresh = block.call write key, fresh, options fresh end
handle_error(key, options, error)
click to toggle source
# File lib/cachext/client.rb, line 43 def handle_error key, options, error @config.error_logger.call error if @config.log_errors? raise if @config.raise_errors && options.reraise_errors end
handle_not_found(key, options, error)
click to toggle source
# File lib/cachext/client.rb, line 39 def handle_not_found key, options, error raise if options.reraise_errors end
read(key, options)
click to toggle source
# File lib/cachext/client.rb, line 48 def read key, options key.read if options.cache? end
write(key, fresh, options)
click to toggle source
# File lib/cachext/client.rb, line 52 def write key, fresh, options key.write fresh, expires_in: options.expires_in if options.cache? end