legion-cache 1.3.6 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83c05e01834ac3a2715494122657a540ab6fb0fc23c4b4645f5b3ecf0198279c
4
- data.tar.gz: e6f944dfa7efa6952810b50766297ce75d39cf6d07bd04af732c8f200e8db051
3
+ metadata.gz: 99c05f6312bd657aa7c85e953e6ec8cbf73ad621953239964a9cb25e7d5ec120
4
+ data.tar.gz: 95292e0a0e278bf124c4e09bc4dc04a41078d3afff7d3484b64d402f825efba6
5
5
  SHA512:
6
- metadata.gz: 79f8620e6101271ab6eb1ec63aecba4a79f2416a2c1b970a1fa02333104a06e6818bc1c7af353a3c5b630d2769834bc9bc8c6a17a4707903cfa4519ffb3884d0
7
- data.tar.gz: 41c24ca832173bce18bd4b58772426f2cb2c798443315aff4fccbd5fc460f9682c60ef15f3e5e83264f89a3bd2d52203eac2f74cd3264e06e1416338077fa5d2
6
+ metadata.gz: 2376fa09e3540aa1044d5eb82169c09a2425fa0cef0d3e597633ab96ed3bff0722e459d3e716383b4b9652bce6c6d4d3883c8afe9df61b6b5e0ba0a7fa0f4fcb
7
+ data.tar.gz: 689a94946a67c949cf436ba6786f05e67e143a73bfac84796cdc9240f9c36d17da4312739f43022c5c69d2d52c6003607224132e0f142f6177e64a879e280938
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.7] - 2026-03-22
4
+
5
+ ### Added
6
+ - Redis driver: `.debug` logging on get (hit/miss), set (ttl/success), delete, flush, mget (key count), mset (key count)
7
+ - Redis driver: `.info` on successful client creation with host/port address
8
+ - Redis driver: private `resolved_redis_address` helper for extracting address at connect time
9
+ - Pool: `.info` on close and restart
10
+ - Cacheable: `.debug` on cache hit/miss in wrapper; `.warn` on swallowed errors in `local_cache_read`/`local_cache_write`
11
+ - Local: `.debug` on get/set/fetch/delete/flush operations
12
+ - Cache: `.info` on successful shared cache setup (driver + server)
13
+ - All new logging calls guarded with `if defined?(Legion::Logging)` for standalone use
14
+
3
15
  ## [1.3.6] - 2026-03-21
4
16
 
5
17
  ### Added
@@ -28,7 +28,12 @@ module Legion
28
28
 
29
29
  unless bypass_local_method_cache
30
30
  cached = Legion::Cache::Cacheable.cache_read(key, scope: config[:scope])
31
- return cached unless cached.nil?
31
+ if cached.nil?
32
+ Legion::Logging.debug "[cacheable] miss key=#{key}" if defined?(Legion::Logging)
33
+ else
34
+ Legion::Logging.debug "[cacheable] hit key=#{key}" if defined?(Legion::Logging)
35
+ return cached
36
+ end
32
37
  end
33
38
 
34
39
  result = super(**kwargs)
@@ -86,7 +91,8 @@ module Legion
86
91
  return nil unless local_cache_available?
87
92
 
88
93
  Legion::Cache::Local.get(key)
89
- rescue StandardError
94
+ rescue StandardError => e
95
+ Legion::Logging.warn "[cacheable] local_cache_read failed key=#{key} error=#{e.message}" if defined?(Legion::Logging)
90
96
  nil
91
97
  end
92
98
 
@@ -94,7 +100,8 @@ module Legion
94
100
  return unless local_cache_available?
95
101
 
96
102
  Legion::Cache::Local.set(key, value, ttl)
97
- rescue StandardError
103
+ rescue StandardError => e
104
+ Legion::Logging.warn "[cacheable] local_cache_write failed key=#{key} error=#{e.message}" if defined?(Legion::Logging)
98
105
  nil
99
106
  end
100
107
 
@@ -36,23 +36,33 @@ module Legion
36
36
  end
37
37
 
38
38
  def get(key)
39
- @driver.get(key)
39
+ result = @driver.get(key)
40
+ Legion::Logging.debug "[cache:local] GET #{key} hit=#{!result.nil?}" if defined?(Legion::Logging)
41
+ result
40
42
  end
41
43
 
42
44
  def set(key, value, ttl = 180)
43
- @driver.set(key, value, ttl)
45
+ result = @driver.set(key, value, ttl)
46
+ Legion::Logging.debug "[cache:local] SET #{key} ttl=#{ttl} success=#{result}" if defined?(Legion::Logging)
47
+ result
44
48
  end
45
49
 
46
50
  def fetch(key, ttl = nil)
47
- @driver.fetch(key, ttl)
51
+ result = @driver.fetch(key, ttl)
52
+ Legion::Logging.debug "[cache:local] FETCH #{key} hit=#{!result.nil?}" if defined?(Legion::Logging)
53
+ result
48
54
  end
49
55
 
50
56
  def delete(key)
51
- @driver.delete(key)
57
+ result = @driver.delete(key)
58
+ Legion::Logging.debug "[cache:local] DELETE #{key} success=#{result}" if defined?(Legion::Logging)
59
+ result
52
60
  end
53
61
 
54
62
  def flush(delay = 0)
55
- @driver.flush(delay)
63
+ result = @driver.flush(delay)
64
+ Legion::Logging.debug '[cache:local] FLUSH completed' if defined?(Legion::Logging)
65
+ result
56
66
  end
57
67
 
58
68
  def client
@@ -31,6 +31,7 @@ module Legion
31
31
  client.shutdown(&:close)
32
32
  @client = nil
33
33
  @connected = false
34
+ Legion::Logging.info "#{name} pool closed" if defined?(Legion::Logging)
34
35
  end
35
36
 
36
37
  def restart(**opts)
@@ -41,6 +42,7 @@ module Legion
41
42
  client_hash[:timeout] = opts[:timeout] if opts.key? :timeout
42
43
  client(**client_hash)
43
44
  @connected = true
45
+ Legion::Logging.info "#{name} pool restarted" if defined?(Legion::Logging)
44
46
  end
45
47
  end
46
48
  end
@@ -23,6 +23,7 @@ module Legion
23
23
  replica: replica, fixed_hostname: fixed_hostname)
24
24
  end
25
25
  @connected = true
26
+ Legion::Logging.info "Redis connected to #{resolved_redis_address(server: server, servers: servers, cluster: cluster)}" if defined?(Legion::Logging)
26
27
  @client
27
28
  end
28
29
 
@@ -49,7 +50,9 @@ module Legion
49
50
  end
50
51
 
51
52
  def get(key)
52
- client.with { |conn| conn.get(key) }
53
+ result = client.with { |conn| conn.get(key) }
54
+ Legion::Logging.debug "[cache] GET #{key} hit=#{!result.nil?}" if defined?(Legion::Logging)
55
+ result
53
56
  rescue ::Redis::BaseError => e
54
57
  log_cluster_error(e)
55
58
  raise
@@ -59,27 +62,33 @@ module Legion
59
62
  def set(key, value, ttl: nil)
60
63
  args = {}
61
64
  args[:ex] = ttl unless ttl.nil?
62
- client.with { |conn| conn.set(key, value, **args) == 'OK' }
65
+ result = client.with { |conn| conn.set(key, value, **args) == 'OK' }
66
+ Legion::Logging.debug "[cache] SET #{key} ttl=#{ttl.inspect} success=#{result}" if defined?(Legion::Logging)
67
+ result
63
68
  rescue ::Redis::BaseError => e
64
69
  log_cluster_error(e)
65
70
  raise
66
71
  end
67
72
 
68
73
  def delete(key)
69
- client.with { |conn| conn.del(key) == 1 }
74
+ result = client.with { |conn| conn.del(key) == 1 }
75
+ Legion::Logging.debug "[cache] DELETE #{key} success=#{result}" if defined?(Legion::Logging)
76
+ result
70
77
  rescue ::Redis::BaseError => e
71
78
  log_cluster_error(e)
72
79
  raise
73
80
  end
74
81
 
75
82
  def flush
76
- client.with do |conn|
83
+ result = client.with do |conn|
77
84
  if cluster_mode?
78
85
  cluster_flush(conn)
79
86
  else
80
87
  conn.flushdb == 'OK'
81
88
  end
82
89
  end
90
+ Legion::Logging.debug '[cache] FLUSH completed' if defined?(Legion::Logging)
91
+ result
83
92
  rescue ::Redis::BaseError => e
84
93
  log_cluster_error(e)
85
94
  raise
@@ -89,14 +98,16 @@ module Legion
89
98
  keys = keys.flatten
90
99
  return {} if keys.empty?
91
100
 
92
- client.with do |conn|
101
+ result = client.with do |conn|
93
102
  if cluster_mode?
94
103
  cluster_mget(conn, keys)
95
104
  else
96
- result = conn.mget(*keys)
97
- keys.zip(result).to_h
105
+ values = conn.mget(*keys)
106
+ keys.zip(values).to_h
98
107
  end
99
108
  end
109
+ Legion::Logging.debug "[cache] MGET keys=#{keys.size}" if defined?(Legion::Logging)
110
+ result
100
111
  rescue ::Redis::BaseError => e
101
112
  log_cluster_error(e)
102
113
  raise
@@ -105,13 +116,15 @@ module Legion
105
116
  def mset(hash)
106
117
  return true if hash.empty?
107
118
 
108
- client.with do |conn|
119
+ result = client.with do |conn|
109
120
  if cluster_mode?
110
121
  cluster_mset(conn, hash)
111
122
  else
112
123
  conn.mset(*hash.flatten) == 'OK'
113
124
  end
114
125
  end
126
+ Legion::Logging.debug "[cache] MSET keys=#{hash.size}" if defined?(Legion::Logging)
127
+ result
115
128
  rescue ::Redis::BaseError => e
116
129
  log_cluster_error(e)
117
130
  raise
@@ -160,6 +173,15 @@ module Legion
160
173
  end
161
174
  end
162
175
 
176
+ def resolved_redis_address(server:, servers:, cluster:)
177
+ nodes = Array(cluster).compact
178
+ return nodes.join(', ') if nodes.any?
179
+
180
+ Legion::Cache::Settings.resolve_servers(driver: 'redis', server: server, servers: Array(servers)).first
181
+ rescue StandardError
182
+ 'unknown'
183
+ end
184
+
163
185
  def log_cluster_error(error)
164
186
  return unless defined?(Legion::Logging)
165
187
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module Cache
5
- VERSION = '1.3.6'
5
+ VERSION = '1.3.7'
6
6
  end
7
7
  end
data/lib/legion/cache.rb CHANGED
@@ -86,6 +86,9 @@ module Legion
86
86
  @connected = true
87
87
  @using_local = false
88
88
  Legion::Settings[:cache][:connected] = true
89
+ driver = Legion::Settings[:cache][:driver] || 'dalli'
90
+ servers = Legion::Settings[:cache][:servers] || []
91
+ Legion::Logging.info "Legion::Cache connected (driver=#{driver} servers=#{Array(servers).first})" if defined?(Legion::Logging)
89
92
  rescue StandardError => e
90
93
  Legion::Logging.warn "Shared cache unavailable (#{e.message}), falling back to Local" if defined?(Legion::Logging)
91
94
  if Legion::Cache::Local.connected?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.6
4
+ version: 1.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity