smart_cache_store 0.1.0 → 0.3.0

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: 5afc7011d21ae7f81c857be6283535b4d036eb126a2a890412c1f98fca5f914a
4
- data.tar.gz: cdc421218f4a6963adbd0f7074c83cfa277d3986f29915482b45dc5ff911e8c0
3
+ metadata.gz: a4bdb9fe3fd3e37388a3acf6b3baf5add0cc5b54fc1a6ba0092c99c1526226b3
4
+ data.tar.gz: 7ff024a2499dd5df7f42bdcbe9f6422eed0e50970e2a146d3d09c35b1fdd9bc6
5
5
  SHA512:
6
- metadata.gz: 70b98d97da2015b7fd4512cf40fdf89aa0b1f3de7b70193cc7db315aaca6055d2754c4dbcd0c465018f9db3866faa48387c76d47eecab9914128f956c2bad5a1
7
- data.tar.gz: '08e1b0c805e7343bf4b07cadbb0703ae7d1383888175246b526f89c85f2cda95f707fae42b7c36712c7d96b4eb7c68bae1d78afb5f0adc8597a6588bb9c4bfd7'
6
+ metadata.gz: 66f840e0521852e358d1be01c186545f0bc920ded0e4509e211111d2f9a142b7464de4fc7032ef3c1d32fc714f4f2fb80593f8eccdd7d584ef6d0bae384c571c
7
+ data.tar.gz: d15389db9cd657838aca3e8fd903e5a1e7a80c978aaca4ee710191acac5b8f5abf7b23a49631ac86efe2b78f6a4d16fc402f96c45d4f1832ebc8d6cf8912adf5
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2021 thomas morgan
1
+ Copyright 2021-2023 thomas morgan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -11,12 +11,11 @@ Set by default:
11
11
  namespace: ENV['REDIS_NAMESPACE']
12
12
  expires_in: 1.day
13
13
  race_condition_ttl: 5.seconds
14
- pool_size: ENV['RAILS_MAX_THREADS'] || 5
14
+ pool: ENV['RAILS_MAX_THREADS'] || 5
15
15
  connect_timeout: 2
16
16
  read_timeout: 1
17
17
  write_timeout: 1
18
- reconnect_attempts: 1
19
- reconnect_delay: 0.2
18
+ reconnect_attempts: [0.2]
20
19
 
21
20
  `:url` should be a uri, like: `redis://localhost:6379/0`. For two or more uris, combine with a comma: `redis://host-a,redis://host-b`.
22
21
 
@@ -32,7 +31,7 @@ Set by default:
32
31
  expires_in: 1.day
33
32
  race_condition_ttl: 5.seconds
34
33
  failover: true
35
- pool_size: ENV['RAILS_MAX_THREADS'] || 5
34
+ pool: ENV['RAILS_MAX_THREADS'] || 5
36
35
 
37
36
  MemCacheStore's legacy initializer with `*addresses` as the first parameter, and the RedisCacheStore compatible `:url` are supported.
38
37
 
@@ -67,9 +66,13 @@ In `environment/[env].rb`:
67
66
 
68
67
 
69
68
  ## Installation
70
- Add this line to your application's Gemfile:
69
+ Add `smart_cache_store` plus one driver to your application's Gemfile:
71
70
 
72
71
  ```ruby
72
+ gem 'redis' # for redis; gem v4.x or 5.x
73
+ # OR
74
+ gem 'dalli' # for memcache
75
+
73
76
  gem "smart_cache_store"
74
77
  ```
75
78
 
@@ -17,7 +17,7 @@ module ActiveSupport
17
17
  # ActiveSupport::Cache - universal options
18
18
  # :namespace{nil}, :compress{true}, :compress_threshold{1k}, :expires_in{0}, :race_condition_ttl{0}
19
19
  # ActiveSupport::Cache::Store
20
- # :pool_size{5}, :pool_timeout{5}
20
+ # :pool{5}, :pool_timeout{5}
21
21
  # Dalli::Client
22
22
  # :failover{true}, :serializer{Marshall}, :compressor{zlib}, :cache_nils{false}
23
23
  # :namespace{nil}, :expires_in{0}, :compress{false} (separate from AS::C's same options above)
@@ -28,34 +28,38 @@ module ActiveSupport
28
28
  expires_in: 1.day,
29
29
  race_condition_ttl: 5.seconds,
30
30
  failover: true,
31
- pool_size: ENV.fetch('RAILS_MAX_THREADS'){ 5 }.to_i,
31
+ pool: ENV.fetch('RAILS_MAX_THREADS'){ 5 }.to_i,
32
32
  )
33
+ args.reverse_merge!(pool_size: args.delete(:pool)) if ActiveSupport.version < '7.1.0.a'
33
34
  addresses.push Array(args.delete(:url)) if addresses.empty? && args.key?(:url)
34
35
  super(*addresses, args)
35
36
  end
36
37
 
37
38
 
38
- # MemCacheStore#increment docs say it will init any invalid value to 0.
39
- # In reality, it will only increment a pre-existing, raw value. everything else returns nil or an error.
40
- # This fixes init of missing value on both increment() and decrement().
41
- # Preexisting, invalid values still return errors.
39
+ if ActiveSupport.version < '7.1.0.a'
40
+ # MemCacheStore#increment docs say it will init any invalid value to 0.
41
+ # In reality, it will only increment a pre-existing, raw value. everything else returns nil or an error.
42
+ # This fixes init of missing value on both increment() and decrement().
43
+ # Preexisting, invalid values still return errors.
42
44
 
43
- def increment(name, amount = 1, options = nil)
44
- options = merged_options(options)
45
- instrument(:increment, name, amount: amount) do
46
- rescue_error_with nil do
47
- @data.with { |c| c.incr(normalize_key(name, options), amount, options[:expires_in], amount) }
45
+ def increment(name, amount = 1, options = nil)
46
+ options = merged_options(options)
47
+ instrument(:increment, name, amount: amount) do
48
+ rescue_error_with nil do
49
+ @data.then { |c| c.incr(normalize_key(name, options), amount, options[:expires_in], amount) }
50
+ end
48
51
  end
49
52
  end
50
- end
51
53
 
52
- def decrement(name, amount = 1, options = nil)
53
- options = merged_options(options)
54
- instrument(:decrement, name, amount: amount) do
55
- rescue_error_with nil do
56
- @data.with { |c| c.decr(normalize_key(name, options), amount, options[:expires_in], 0) }
54
+ def decrement(name, amount = 1, options = nil)
55
+ options = merged_options(options)
56
+ instrument(:decrement, name, amount: amount) do
57
+ rescue_error_with nil do
58
+ @data.then { |c| c.decr(normalize_key(name, options), amount, options[:expires_in], 0) }
59
+ end
57
60
  end
58
61
  end
62
+
59
63
  end
60
64
 
61
65
  end
@@ -15,26 +15,36 @@ module ActiveSupport
15
15
  # ActiveSupport::Cache - universal options
16
16
  # :namespace{nil}, :compress{true}, :compress_threshold{1k}, :expires_in{0}, :race_condition_ttl{0}
17
17
  # ActiveSupport::Cache::Store
18
- # :pool_size{5}, :pool_timeout{5}
18
+ # :pool{5}, :pool_timeout{5}
19
19
  # Redis
20
20
  # :host, :port, :db, :username, :password, :url, :path
21
21
  # ssl_params: {:ca_file, :cert, :key}
22
22
  # :sentinels, :role
23
- # :cluster, :replica
23
+ # :replica
24
24
  # :timeout (sets next 3), :connect_timeout, :read_timeout, :write_timeout
25
- # :reconnect_attempts, :reconnect_delay, :reconnect_delay_max
25
+ # :reconnect_attempts
26
26
  def initialize(**args)
27
27
  args.reverse_merge!(
28
28
  namespace: ENV['REDIS_NAMESPACE'],
29
29
  expires_in: 1.day,
30
30
  race_condition_ttl: 5.seconds,
31
- pool_size: ENV.fetch('RAILS_MAX_THREADS'){ 5 }.to_i,
31
+ pool: ENV.fetch('RAILS_MAX_THREADS'){ 5 }.to_i,
32
32
  connect_timeout: 2,
33
33
  read_timeout: 1,
34
34
  write_timeout: 1,
35
- reconnect_attempts: 1,
36
- reconnect_delay: 0.2,
37
35
  )
36
+ args.reverse_merge!(pool_size: args.delete(:pool)) if ActiveSupport.version < '7.1.0.a'
37
+ if Redis::VERSION >= '5'
38
+ args.reverse_merge!(
39
+ # when an array, contains delay for each reconnect attempt
40
+ reconnect_attempts: [0.2]
41
+ )
42
+ else
43
+ args.reverse_merge!(
44
+ reconnect_attempts: 1,
45
+ reconnect_delay: 0.2,
46
+ )
47
+ end
38
48
  args[:url] ||= ENV['REDIS_URL'] unless args.key?(:redis) || args.key?(:url)
39
49
  args[:url] = args[:url].split(',') if args[:url].is_a?(String)
40
50
  super(**args)
@@ -1,3 +1,3 @@
1
1
  module SmartCacheStore
2
- VERSION = '0.1.0'
2
+ VERSION = '0.3.0'
3
3
  end
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-18 00:00:00.000000000 Z
11
+ date: 2023-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,7 +24,22 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.2'
27
- description:
27
+ - !ruby/object:Gem::Dependency
28
+ name: connection_pool
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.4
41
+ description: Production-ready enhancements for mem_cache_store and redis_cache_store.
42
+ For Rails or ActiveSupport.
28
43
  email:
29
44
  - tm@iprog.com
30
45
  executables: []
@@ -60,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
75
  - !ruby/object:Gem::Version
61
76
  version: '0'
62
77
  requirements: []
63
- rubygems_version: 3.2.22
78
+ rubygems_version: 3.3.26
64
79
  signing_key:
65
80
  specification_version: 4
66
81
  summary: Production-ready enhancements for mem_cache_store and redis_cache_store