Class: RedisMemo::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_memo/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(async: nil, compress: nil, compress_threshold: nil, redis: nil, redis_error_handler: nil, tracer: nil, global_cache_key_version: nil, expires_in: nil) ⇒ Options

Returns a new instance of Options.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/redis_memo/options.rb', line 4

def initialize(
  async: nil,
  compress: nil,
  compress_threshold: nil,
  redis: nil,
  redis_error_handler: nil,
  tracer: nil,
  global_cache_key_version: nil,
  expires_in: nil
)
  @compress = compress.nil? ? true : compress
  @compress_threshold = compress_threshold || 1.kilobyte
  @redis_config = redis
  @redis_client = nil
  @redis_error_handler = redis_error_handler
  @tracer = tracer
  @logger = logger
  @global_cache_key_version = global_cache_key_version
  @expires_in = expires_in
end

Instance Attribute Details

#asyncObject

Returns the value of attribute async.



74
75
76
# File 'lib/redis_memo/options.rb', line 74

def async
  @async
end

#cache_out_of_date_handlerObject

Returns the value of attribute cache_out_of_date_handler.



75
76
77
# File 'lib/redis_memo/options.rb', line 75

def cache_out_of_date_handler
  @cache_out_of_date_handler
end

#cache_validation_samplerObject

Returns the value of attribute cache_validation_sampler.



76
77
78
# File 'lib/redis_memo/options.rb', line 76

def cache_validation_sampler
  @cache_validation_sampler
end

#compressObject

Returns the value of attribute compress.



77
78
79
# File 'lib/redis_memo/options.rb', line 77

def compress
  @compress
end

#compress_thresholdObject

Returns the value of attribute compress_threshold.



78
79
80
# File 'lib/redis_memo/options.rb', line 78

def compress_threshold
  @compress_threshold
end

#connection_poolObject

Returns the value of attribute connection_pool.



79
80
81
# File 'lib/redis_memo/options.rb', line 79

def connection_pool
  @connection_pool
end

#expires_inObject

Returns the value of attribute expires_in.



80
81
82
# File 'lib/redis_memo/options.rb', line 80

def expires_in
  @expires_in
end

#global_cache_key_version(&blk) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/redis_memo/options.rb', line 59

def global_cache_key_version(&blk)
  # this method takes a block to be consistent with the inline memo_method
  # API
  if blk.nil?
    if !@global_cache_key_version.respond_to?(:call)
      return @global_cache_key_version
    end

    @global_cache_key_version&.call
  else
    # save the global cache_key_version eagerly
    @global_cache_key_version = blk
  end
end

#logger(&blk) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/redis_memo/options.rb', line 49

def logger(&blk)
  if blk.nil?
    return @logger if @logger.respond_to?(:warn)

    @logger&.call
  else
    @logger = blk
  end
end

#redis_error_handlerObject

Returns the value of attribute redis_error_handler.



81
82
83
# File 'lib/redis_memo/options.rb', line 81

def redis_error_handler
  @redis_error_handler
end

#tracer(&blk) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/redis_memo/options.rb', line 39

def tracer(&blk)
  if blk.nil?
    return @tracer if @tracer.respond_to?(:trace)

    @tracer&.call
  else
    @tracer = blk
  end
end

Instance Method Details

#redisObject



25
26
27
# File 'lib/redis_memo/options.rb', line 25

def redis
  @redis_client ||= RedisMemo::Redis.new(redis_config)
end

#redis=(config) ⇒ Object



33
34
35
36
37
# File 'lib/redis_memo/options.rb', line 33

def redis=(config)
  @redis_config = config
  @redis_client = nil
  redis
end

#redis_configObject



29
30
31
# File 'lib/redis_memo/options.rb', line 29

def redis_config
  @redis_config || {}
end