smart_cache_store 0.2.0 → 0.3.1
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/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/lib/active_support/cache/smart_mem_cache.rb +27 -18
- data/lib/active_support/cache/smart_redis_cache.rb +13 -5
- data/lib/smart_cache_store/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1880ca4e20a7e99d8a3241e895a9e8405f17faf2e1d28ddede62b8acde1d4c16
|
4
|
+
data.tar.gz: 9e7d77179cd5c0b020a583b92256b7900fe886cb054947e4e84eaead557f8833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31630bf7314ebf8b6b065e885e2604b1faa9e50444d7f5aef361260a570e208fb0b412e7f942dc151c5547eb0e3bfd02344ee261b6b3af35af0d8fc43e7792c7
|
7
|
+
data.tar.gz: 1e0b2ce48c0c902bcf5ebaab820e0bdc84d482ee6a22c51fcb017b91e8581ed445c12ac0b0b38aca191e28296ef28c641630bafd08a7d97297038fa0e4f8b0d3
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Set by default:
|
|
11
11
|
namespace: ENV['REDIS_NAMESPACE']
|
12
12
|
expires_in: 1.day
|
13
13
|
race_condition_ttl: 5.seconds
|
14
|
-
|
14
|
+
pool: ENV['RAILS_MAX_THREADS'] || 5
|
15
15
|
connect_timeout: 2
|
16
16
|
read_timeout: 1
|
17
17
|
write_timeout: 1
|
@@ -31,7 +31,7 @@ Set by default:
|
|
31
31
|
expires_in: 1.day
|
32
32
|
race_condition_ttl: 5.seconds
|
33
33
|
failover: true
|
34
|
-
|
34
|
+
pool: ENV['RAILS_MAX_THREADS'] || 5
|
35
35
|
|
36
36
|
MemCacheStore's legacy initializer with `*addresses` as the first parameter, and the RedisCacheStore compatible `:url` are supported.
|
37
37
|
|
@@ -15,9 +15,10 @@ module ActiveSupport
|
|
15
15
|
|
16
16
|
# known options:
|
17
17
|
# ActiveSupport::Cache - universal options
|
18
|
-
# :namespace{nil}, :compress{true}, :compress_threshold{1k}, :
|
18
|
+
# :namespace{nil}, :compress{true}, :compress_threshold{1k}, :coder, :expires_in{0}
|
19
|
+
# :race_condition_ttl{0}, :skip_nil{false}
|
19
20
|
# ActiveSupport::Cache::Store
|
20
|
-
# :
|
21
|
+
# pool: {:size{5}, :timeout{5}}
|
21
22
|
# Dalli::Client
|
22
23
|
# :failover{true}, :serializer{Marshall}, :compressor{zlib}, :cache_nils{false}
|
23
24
|
# :namespace{nil}, :expires_in{0}, :compress{false} (separate from AS::C's same options above)
|
@@ -28,34 +29,42 @@ module ActiveSupport
|
|
28
29
|
expires_in: 1.day,
|
29
30
|
race_condition_ttl: 5.seconds,
|
30
31
|
failover: true,
|
31
|
-
pool_size: ENV.fetch('RAILS_MAX_THREADS'){ 5 }.to_i,
|
32
32
|
)
|
33
|
+
if ActiveSupport.version >= '7.1.0.a'
|
34
|
+
args[:pool] ||= {}
|
35
|
+
args[:pool][:size] ||= Integer(ENV.fetch('RAILS_MAX_THREADS'){ 5 })
|
36
|
+
else
|
37
|
+
args[:pool_size] ||= Integer(ENV.fetch('RAILS_MAX_THREADS'){ 5 })
|
38
|
+
end
|
33
39
|
addresses.push Array(args.delete(:url)) if addresses.empty? && args.key?(:url)
|
34
40
|
super(*addresses, args)
|
35
41
|
end
|
36
42
|
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
if ActiveSupport.version < '7.1.0.a'
|
45
|
+
# MemCacheStore#increment docs say it will init any invalid value to 0.
|
46
|
+
# In reality, it will only increment a pre-existing, raw value. everything else returns nil or an error.
|
47
|
+
# This fixes init of missing value on both increment() and decrement().
|
48
|
+
# Preexisting, invalid values still return errors.
|
42
49
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
def increment(name, amount = 1, options = nil)
|
51
|
+
options = merged_options(options)
|
52
|
+
instrument(:increment, name, amount: amount) do
|
53
|
+
rescue_error_with nil do
|
54
|
+
@data.then { |c| c.incr(normalize_key(name, options), amount, options[:expires_in], amount) }
|
55
|
+
end
|
48
56
|
end
|
49
57
|
end
|
50
|
-
end
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
def decrement(name, amount = 1, options = nil)
|
60
|
+
options = merged_options(options)
|
61
|
+
instrument(:decrement, name, amount: amount) do
|
62
|
+
rescue_error_with nil do
|
63
|
+
@data.then { |c| c.decr(normalize_key(name, options), amount, options[:expires_in], 0) }
|
64
|
+
end
|
57
65
|
end
|
58
66
|
end
|
67
|
+
|
59
68
|
end
|
60
69
|
|
61
70
|
end
|
@@ -13,26 +13,34 @@ module ActiveSupport
|
|
13
13
|
|
14
14
|
# known options:
|
15
15
|
# ActiveSupport::Cache - universal options
|
16
|
-
# :namespace{nil}, :compress{true}, :compress_threshold{1k}, :
|
16
|
+
# :namespace{nil}, :compress{true}, :compress_threshold{1k}, :coder, :expires_in{0}
|
17
|
+
# :race_condition_ttl{0}, :skip_nil{false}
|
17
18
|
# ActiveSupport::Cache::Store
|
18
|
-
# :
|
19
|
+
# pool: {:size{5}, :timeout{5}}
|
20
|
+
# ActiveSupport::Cache::RedisCacheStore
|
21
|
+
# :error_handler
|
19
22
|
# Redis
|
20
23
|
# :host, :port, :db, :username, :password, :url, :path
|
21
24
|
# ssl_params: {:ca_file, :cert, :key}
|
22
25
|
# :sentinels, :role
|
23
|
-
# :
|
26
|
+
# :replica
|
24
27
|
# :timeout (sets next 3), :connect_timeout, :read_timeout, :write_timeout
|
25
|
-
# :reconnect_attempts
|
28
|
+
# :reconnect_attempts
|
26
29
|
def initialize(**args)
|
27
30
|
args.reverse_merge!(
|
28
31
|
namespace: ENV['REDIS_NAMESPACE'],
|
29
32
|
expires_in: 1.day,
|
30
33
|
race_condition_ttl: 5.seconds,
|
31
|
-
pool_size: ENV.fetch('RAILS_MAX_THREADS'){ 5 }.to_i,
|
32
34
|
connect_timeout: 2,
|
33
35
|
read_timeout: 1,
|
34
36
|
write_timeout: 1,
|
35
37
|
)
|
38
|
+
if ActiveSupport.version >= '7.1.0.a'
|
39
|
+
args[:pool] ||= {}
|
40
|
+
args[:pool][:size] ||= Integer(ENV.fetch('RAILS_MAX_THREADS'){ 5 })
|
41
|
+
else
|
42
|
+
args[:pool_size] ||= Integer(ENV.fetch('RAILS_MAX_THREADS'){ 5 })
|
43
|
+
end
|
36
44
|
if Redis::VERSION >= '5'
|
37
45
|
args.reverse_merge!(
|
38
46
|
# when an array, contains delay for each reconnect attempt
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_cache_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
78
|
+
rubygems_version: 3.4.10
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Production-ready enhancements for mem_cache_store and redis_cache_store
|