legion-cache 1.3.13 → 1.3.15
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/legion/cache/redis.rb +14 -5
- data/lib/legion/cache/settings.rb +37 -29
- data/lib/legion/cache/version.rb +1 -1
- data/lib/legion/cache.rb +20 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d143549258e7e7a2ec8d3ff702a724eb98648582a442c594bd8df360f8fd1c5
|
|
4
|
+
data.tar.gz: cff229d7de54b78aa9b3995a8fa9d5877e059ab32059fadb786b786357fbebaf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 073ea47e6e2c886388fa980f490cf395bbfe3be1a90129cc3d804ea5df36d7c8ee814e725e1bcaae94b35d840c0729b47ab5181d5c7f12581e2c3664d76a74b3
|
|
7
|
+
data.tar.gz: 82599629d8df3d385c96001321e55c123670154cbc72e243ded365d4f22d93dc085e19bfa2605fb377fab69e0be21291d46937450702d1b4a70860e41d06efde
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.15] - 2026-03-24
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- PHI-aware TTL enforcement: `Cache.set` accepts `phi: true` keyword option; TTL is capped at `cache.compliance.phi_max_ttl` (default 3600s) when set
|
|
7
|
+
- `Legion::Cache.phi_max_ttl` — reads `cache.compliance.phi_max_ttl` from settings with 3600s default
|
|
8
|
+
- `Legion::Cache.enforce_phi_ttl(ttl, phi:)` — public helper for PHI TTL cap logic
|
|
9
|
+
|
|
10
|
+
## [1.3.14] - 2026-03-24
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `username`, `password`, `db`, and `reconnect_attempts` options to Redis `client` and `build_redis_client`
|
|
14
|
+
- Corresponding nil/default entries in `Settings.default` and `Settings.local`
|
|
15
|
+
|
|
3
16
|
## [1.3.13] - 2026-03-24
|
|
4
17
|
|
|
5
18
|
### Changed
|
data/lib/legion/cache/redis.rb
CHANGED
|
@@ -11,7 +11,8 @@ module Legion
|
|
|
11
11
|
include Legion::Cache::Pool
|
|
12
12
|
extend self
|
|
13
13
|
|
|
14
|
-
def client(pool_size: 20, timeout: 5, server: nil, servers: [], cluster: nil, replica: false,
|
|
14
|
+
def client(pool_size: 20, timeout: 5, server: nil, servers: [], cluster: nil, replica: false, # rubocop:disable Metrics/ParameterLists
|
|
15
|
+
fixed_hostname: nil, username: nil, password: nil, db: nil, reconnect_attempts: 1, **)
|
|
15
16
|
return @client unless @client.nil?
|
|
16
17
|
|
|
17
18
|
@pool_size = pool_size
|
|
@@ -20,26 +21,34 @@ module Legion
|
|
|
20
21
|
|
|
21
22
|
@client = ConnectionPool.new(size: pool_size, timeout: timeout) do
|
|
22
23
|
build_redis_client(server: server, servers: servers, cluster: cluster,
|
|
23
|
-
replica: replica, fixed_hostname: fixed_hostname
|
|
24
|
+
replica: replica, fixed_hostname: fixed_hostname,
|
|
25
|
+
username: username, password: password, db: db,
|
|
26
|
+
reconnect_attempts: reconnect_attempts)
|
|
24
27
|
end
|
|
25
28
|
@connected = true
|
|
26
29
|
Legion::Logging.info "Redis connected to #{resolved_redis_address(server: server, servers: servers, cluster: cluster)}" if defined?(Legion::Logging)
|
|
27
30
|
@client
|
|
28
31
|
end
|
|
29
32
|
|
|
30
|
-
def build_redis_client(server: nil, servers: [], cluster: nil, replica: false, fixed_hostname: nil
|
|
33
|
+
def build_redis_client(server: nil, servers: [], cluster: nil, replica: false, fixed_hostname: nil, # rubocop:disable Metrics/ParameterLists
|
|
34
|
+
username: nil, password: nil, db: nil, reconnect_attempts: 1)
|
|
31
35
|
nodes = Array(cluster).compact
|
|
32
36
|
if nodes.any?
|
|
33
|
-
opts = { cluster: nodes }
|
|
37
|
+
opts = { cluster: nodes, reconnect_attempts: reconnect_attempts }
|
|
34
38
|
opts[:replica] = true if replica
|
|
35
39
|
opts[:fixed_hostname] = fixed_hostname unless fixed_hostname.nil?
|
|
40
|
+
opts[:username] = username unless username.nil?
|
|
41
|
+
opts[:password] = password unless password.nil?
|
|
36
42
|
::Redis.new(**opts)
|
|
37
43
|
else
|
|
38
44
|
resolved = Legion::Cache::Settings.resolve_servers(
|
|
39
45
|
driver: 'redis', server: server, servers: servers
|
|
40
46
|
)
|
|
41
47
|
host, port = resolved.first.split(':')
|
|
42
|
-
redis_opts = { host: host, port: port.to_i }
|
|
48
|
+
redis_opts = { host: host, port: port.to_i, reconnect_attempts: reconnect_attempts }
|
|
49
|
+
redis_opts[:username] = username unless username.nil?
|
|
50
|
+
redis_opts[:password] = password unless password.nil?
|
|
51
|
+
redis_opts[:db] = db unless db.nil?
|
|
43
52
|
redis_opts.merge!(redis_tls_options(port: port.to_i))
|
|
44
53
|
::Redis.new(**redis_opts)
|
|
45
54
|
end
|
|
@@ -13,40 +13,48 @@ module Legion
|
|
|
13
13
|
Legion::Settings.merge_settings(:cache_local, local) if Legion::Settings.method_defined? :merge_settings
|
|
14
14
|
def self.default
|
|
15
15
|
{
|
|
16
|
-
driver:
|
|
17
|
-
servers:
|
|
18
|
-
connected:
|
|
19
|
-
enabled:
|
|
20
|
-
namespace:
|
|
21
|
-
compress:
|
|
22
|
-
failover:
|
|
23
|
-
threadsafe:
|
|
24
|
-
expires_in:
|
|
25
|
-
cache_nils:
|
|
26
|
-
pool_size:
|
|
27
|
-
timeout:
|
|
28
|
-
serializer:
|
|
29
|
-
cluster:
|
|
30
|
-
replica:
|
|
31
|
-
fixed_hostname:
|
|
16
|
+
driver: driver,
|
|
17
|
+
servers: resolve_servers(driver: driver),
|
|
18
|
+
connected: false,
|
|
19
|
+
enabled: true,
|
|
20
|
+
namespace: 'legion',
|
|
21
|
+
compress: false,
|
|
22
|
+
failover: true,
|
|
23
|
+
threadsafe: true,
|
|
24
|
+
expires_in: 0,
|
|
25
|
+
cache_nils: false,
|
|
26
|
+
pool_size: 10,
|
|
27
|
+
timeout: 5,
|
|
28
|
+
serializer: Legion::JSON,
|
|
29
|
+
cluster: nil,
|
|
30
|
+
replica: false,
|
|
31
|
+
fixed_hostname: nil,
|
|
32
|
+
username: nil,
|
|
33
|
+
password: nil,
|
|
34
|
+
db: nil,
|
|
35
|
+
reconnect_attempts: 1
|
|
32
36
|
}
|
|
33
37
|
end
|
|
34
38
|
|
|
35
39
|
def self.local
|
|
36
40
|
{
|
|
37
|
-
driver:
|
|
38
|
-
servers:
|
|
39
|
-
connected:
|
|
40
|
-
enabled:
|
|
41
|
-
namespace:
|
|
42
|
-
compress:
|
|
43
|
-
failover:
|
|
44
|
-
threadsafe:
|
|
45
|
-
expires_in:
|
|
46
|
-
cache_nils:
|
|
47
|
-
pool_size:
|
|
48
|
-
timeout:
|
|
49
|
-
serializer:
|
|
41
|
+
driver: driver,
|
|
42
|
+
servers: resolve_servers(driver: driver),
|
|
43
|
+
connected: false,
|
|
44
|
+
enabled: true,
|
|
45
|
+
namespace: 'legion_local',
|
|
46
|
+
compress: false,
|
|
47
|
+
failover: true,
|
|
48
|
+
threadsafe: true,
|
|
49
|
+
expires_in: 0,
|
|
50
|
+
cache_nils: false,
|
|
51
|
+
pool_size: 5,
|
|
52
|
+
timeout: 3,
|
|
53
|
+
serializer: Legion::JSON,
|
|
54
|
+
username: nil,
|
|
55
|
+
password: nil,
|
|
56
|
+
db: nil,
|
|
57
|
+
reconnect_attempts: 1
|
|
50
58
|
}
|
|
51
59
|
end
|
|
52
60
|
|
data/lib/legion/cache/version.rb
CHANGED
data/lib/legion/cache.rb
CHANGED
|
@@ -64,11 +64,27 @@ module Legion
|
|
|
64
64
|
super
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
def
|
|
68
|
-
return Legion::
|
|
69
|
-
return Legion::Cache::Local.set(key, value, ttl) if @using_local
|
|
67
|
+
def phi_max_ttl
|
|
68
|
+
return 3600 unless defined?(Legion::Settings)
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
Legion::Settings.dig(:cache, :compliance, :phi_max_ttl) || 3600
|
|
71
|
+
rescue StandardError
|
|
72
|
+
3600
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def enforce_phi_ttl(ttl, phi: false, **)
|
|
76
|
+
return ttl unless phi == true
|
|
77
|
+
|
|
78
|
+
max = phi_max_ttl
|
|
79
|
+
[ttl, max].min
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def set(key, value, ttl = 180, **)
|
|
83
|
+
effective_ttl = enforce_phi_ttl(ttl, **)
|
|
84
|
+
return Legion::Cache::Memory.set(key, value, effective_ttl) if @using_memory
|
|
85
|
+
return Legion::Cache::Local.set(key, value, effective_ttl) if @using_local
|
|
86
|
+
|
|
87
|
+
super(key, value, effective_ttl)
|
|
72
88
|
end
|
|
73
89
|
|
|
74
90
|
def fetch(key, ttl = nil)
|