smart_cache_store 1.0.0 → 2.0.0.rc1
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 +48 -40
- data/lib/active_support/cache/smart_mem_cache.rb +8 -36
- data/lib/active_support/cache/smart_redis_cache.rb +19 -31
- data/lib/smart_cache_store/version.rb +1 -1
- metadata +12 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4d3fcd8e25a296657f0f5207801f2514facf5754a9012e500dcc525e2fdf311
|
|
4
|
+
data.tar.gz: dd6a27c97e087d7e39d517b3ed0c5a16f05644142f91fc57f051284745f5bf4a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 294e4f7b8cc6b81146e011ae8120c73f0751df2195e7874e07219ff0aa1e749a9442bdaa85e40ecebfaf740d2c822c2cc2eb0eea9aa014259b65dacbcedc2c37
|
|
7
|
+
data.tar.gz: 3f686656fd3d5c2173eb6003a126273ad65713df3b9c775fc4e8b3e6949ccbf31b9dac6b99b9c4ffafd1ed464ce9a46e140c7bd662604853e6219ca5e2f89d89
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,67 +1,69 @@
|
|
|
1
1
|
# SmartCacheStore
|
|
2
2
|
|
|
3
|
-
SmartCacheStore provides variations on ActiveSupport's
|
|
3
|
+
SmartCacheStore provides variations on ActiveSupport's RedisCacheStore and MemCacheStore to make the default configurations more production ready. It does this by setting better defaults and using a few more ENVs.
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
##### Redis -- SmartRedisCache
|
|
6
|
+
##### Redis/Valkey -- SmartRedisCache
|
|
7
7
|
|
|
8
8
|
Set by default:
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
```ruby
|
|
11
|
+
url: ENV['REDIS_URL']
|
|
12
|
+
namespace: ENV['REDIS_NAMESPACE']
|
|
13
|
+
expires_in: 1.day
|
|
14
|
+
race_condition_ttl: 5.seconds
|
|
15
|
+
pool: { size: ENV['RAILS_MAX_THREADS'] || 5 }
|
|
16
|
+
connect_timeout: 0.5
|
|
17
|
+
read_timeout: 1
|
|
18
|
+
write_timeout: 1
|
|
19
|
+
reconnect_attempts: [0.2]
|
|
20
|
+
```
|
|
19
21
|
|
|
20
22
|
`: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`.
|
|
21
23
|
|
|
22
|
-
Any of these may still be specified directly, as well as all other support parameters for RedisCacheStore or the Redis gem.
|
|
23
|
-
|
|
24
24
|
|
|
25
25
|
##### Memcache -- SmartMemCache
|
|
26
26
|
|
|
27
27
|
Set by default:
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`:url` or *addresses should be a uri, like: `memcached://localhost:11211`. For two or more uris, combine with a comma: `memcached://host-a,memcached://host-b`.
|
|
39
|
-
|
|
29
|
+
```ruby
|
|
30
|
+
url: ENV['MEMCACHE_SERVERS']
|
|
31
|
+
namespace: ENV['MEMCACHE_NAMESPACE']
|
|
32
|
+
expires_in: 1.day
|
|
33
|
+
race_condition_ttl: 5.seconds
|
|
34
|
+
failover: true
|
|
35
|
+
pool: { size: ENV['RAILS_MAX_THREADS'] || 5 }
|
|
36
|
+
```
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
MemCacheStore's legacy initializer with `*addresses` as the first parameter, and the RedisCacheStore compatible `:url` are supported. See examples below.
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
`:url` or `*addresses` should be a uri, like: `memcached://localhost:11211`. For two or more uris, combine with a comma: `memcached://host-a,memcached://host-b`.
|
|
44
41
|
|
|
45
42
|
|
|
46
43
|
## Usage
|
|
47
44
|
|
|
48
45
|
In `environment/[env].rb`:
|
|
49
46
|
|
|
50
|
-
#### Redis
|
|
47
|
+
#### Redis/Valkey
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
```ruby
|
|
50
|
+
# basic:
|
|
51
|
+
config.cache_store = :smart_redis_cache
|
|
52
|
+
# with parameters:
|
|
53
|
+
config.cache_store = :smart_redis_cache, {url: 'redis://localhost:1234/9'}
|
|
54
|
+
config.cache_store = :smart_redis_cache, {url: 'redis://localhost:1234/9', connect_timeout: 1}
|
|
55
|
+
```
|
|
56
56
|
|
|
57
57
|
#### Memcache
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
```ruby
|
|
60
|
+
# basic:
|
|
61
|
+
config.cache_store = :smart_mem_cache
|
|
62
|
+
# with parameters:
|
|
63
|
+
config.cache_store = :smart_mem_cache, 'memcached://localhost:1234'
|
|
64
|
+
config.cache_store = :smart_mem_cache, 'memcached://localhost:1234', {expires_in: 1.hour}
|
|
65
|
+
config.cache_store = :smart_mem_cache, {url: 'memcached://localhost:1234', expires_in: 1.hour}
|
|
66
|
+
```
|
|
65
67
|
|
|
66
68
|
|
|
67
69
|
|
|
@@ -69,19 +71,25 @@ In `environment/[env].rb`:
|
|
|
69
71
|
Add `smart_cache_store` plus one driver to your application's Gemfile:
|
|
70
72
|
|
|
71
73
|
```ruby
|
|
72
|
-
gem 'redis' # for redis
|
|
74
|
+
gem 'redis-client' # for redis/valkey
|
|
73
75
|
# OR
|
|
74
76
|
gem 'dalli' # for memcache
|
|
75
77
|
|
|
76
|
-
gem
|
|
78
|
+
gem 'smart_cache_store'
|
|
77
79
|
```
|
|
78
80
|
|
|
79
81
|
And then execute:
|
|
80
82
|
```bash
|
|
81
|
-
$ bundle
|
|
83
|
+
$ bundle install
|
|
82
84
|
```
|
|
83
85
|
|
|
84
86
|
|
|
87
|
+
## Gem versions
|
|
88
|
+
|
|
89
|
+
For Rails / ActiveSupport >= 8.2, use smart_cache_store 2.x.
|
|
90
|
+
For Rails / ActiveSupport 6.1-8.1, use smart_cache_store 1.x.
|
|
91
|
+
|
|
92
|
+
|
|
85
93
|
## Contributing
|
|
86
94
|
|
|
87
95
|
1. Fork it ( https://github.com/zarqman/smart_cache_store/fork )
|
|
@@ -15,12 +15,15 @@ module ActiveSupport
|
|
|
15
15
|
|
|
16
16
|
# known options:
|
|
17
17
|
# ActiveSupport::Cache - universal options
|
|
18
|
-
# :
|
|
19
|
-
# :race_condition_ttl{0}, :
|
|
18
|
+
# :coder, :compress{true}, :compress_threshold{1024}, :compressor{Zlib},
|
|
19
|
+
# :expires_in{0}, :namespace{nil}, :race_condition_ttl{0}, :serializer{Marshal},
|
|
20
|
+
# :skip_nil{false}, :raw{false}, :max_key_size{250}
|
|
20
21
|
# ActiveSupport::Cache::Store
|
|
21
22
|
# pool: {:size{5}, :timeout{5}}
|
|
23
|
+
# ActiveSupport::Cache::MemCacheStore
|
|
24
|
+
# :cache_nils
|
|
22
25
|
# Dalli::Client
|
|
23
|
-
# :failover{true}, :serializer{
|
|
26
|
+
# :failover{true}, :serializer{Marshal}, :compressor{Zlib}, :cache_nils{false}
|
|
24
27
|
# :namespace{nil}, :expires_in{0}, :compress{false} (separate from AS::C's same options above)
|
|
25
28
|
# :threadsafe{true} (using ConnPool turns this off automatically)
|
|
26
29
|
def initialize(*addresses, **args)
|
|
@@ -30,43 +33,12 @@ module ActiveSupport
|
|
|
30
33
|
race_condition_ttl: 5.seconds,
|
|
31
34
|
failover: true,
|
|
32
35
|
)
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
36
|
+
args[:pool] ||= {}
|
|
37
|
+
args[:pool][:size] ||= Integer(ENV.fetch('RAILS_MAX_THREADS'){ 5 })
|
|
39
38
|
addresses.push Array(args.delete(:url)) if addresses.empty? && args.key?(:url)
|
|
40
39
|
super(*addresses, args)
|
|
41
40
|
end
|
|
42
41
|
|
|
43
|
-
|
|
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.
|
|
49
|
-
|
|
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.with { |c| c.incr(normalize_key(name, options), amount, options[:expires_in], amount) }
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
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.with { |c| c.decr(normalize_key(name, options), amount, options[:expires_in], 0) }
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
|
|
70
42
|
end
|
|
71
43
|
end
|
|
72
44
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# requires gems: redis, connection_pool
|
|
1
|
+
# requires gems: redis-client, connection_pool
|
|
2
2
|
#
|
|
3
3
|
# REDIS_URL (or :url) can have one or multiple urls:
|
|
4
4
|
# redis://localhost:1234
|
|
5
|
-
# redis://host-a,redis://host-b # automatically uses
|
|
5
|
+
# redis://host-a,redis://host-b # automatically uses RedisClient::HashRing
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
require 'active_support/cache/redis_cache_store'
|
|
@@ -13,46 +13,34 @@ module ActiveSupport
|
|
|
13
13
|
|
|
14
14
|
# known options:
|
|
15
15
|
# ActiveSupport::Cache - universal options
|
|
16
|
-
# :
|
|
17
|
-
# :race_condition_ttl{0}, :
|
|
16
|
+
# :coder, :compress{true}, :compress_threshold{1024}, :compressor{Zlib},
|
|
17
|
+
# :expires_in{0}, :namespace{nil}, :race_condition_ttl{0}, :serializer{Marshal},
|
|
18
|
+
# :skip_nil{false}, :raw{false}, :max_key_size{250}
|
|
18
19
|
# ActiveSupport::Cache::Store
|
|
19
20
|
# pool: {:size{5}, :timeout{5}}
|
|
20
21
|
# ActiveSupport::Cache::RedisCacheStore
|
|
21
|
-
# :error_handler
|
|
22
|
-
#
|
|
23
|
-
# :
|
|
24
|
-
#
|
|
25
|
-
# :
|
|
26
|
-
# :
|
|
27
|
-
# :
|
|
28
|
-
# :reconnect_attempts
|
|
22
|
+
# :client, :error_handler
|
|
23
|
+
# RedisClient
|
|
24
|
+
# :url, :host{localhost}, :port{6379}, :path
|
|
25
|
+
# :username{nil}, :password{nil}, :db{0}, :id{nil}
|
|
26
|
+
# :timeout{1} (sets next 3 ->), :connect_timeout{1}, :read_timeout{1}, :write_timeout{1}
|
|
27
|
+
# :idle_timeout{30}, :custom{{}}
|
|
28
|
+
# :ssl{false}, ssl_params: {:ca_file, :cert, :key, :verify_hostname}
|
|
29
|
+
# :protocol{2}, :reconnect_attempts{0}, :middlewares{[]}, :circuit_breaker{nil}
|
|
30
|
+
# for sentinels or cluster, build directly and pass in as :client
|
|
29
31
|
def initialize(**args)
|
|
30
32
|
args.reverse_merge!(
|
|
31
33
|
namespace: ENV['REDIS_NAMESPACE'],
|
|
32
34
|
expires_in: 1.day,
|
|
33
35
|
race_condition_ttl: 5.seconds,
|
|
34
|
-
connect_timeout:
|
|
36
|
+
connect_timeout: 0.5,
|
|
35
37
|
read_timeout: 1,
|
|
36
38
|
write_timeout: 1,
|
|
39
|
+
reconnect_attempts: [0.2],
|
|
37
40
|
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
else
|
|
42
|
-
args[:pool_size] ||= Integer(ENV.fetch('RAILS_MAX_THREADS'){ 5 })
|
|
43
|
-
end
|
|
44
|
-
if Redis::VERSION >= '5'
|
|
45
|
-
args.reverse_merge!(
|
|
46
|
-
# when an array, contains delay for each reconnect attempt
|
|
47
|
-
reconnect_attempts: [0.2]
|
|
48
|
-
)
|
|
49
|
-
else
|
|
50
|
-
args.reverse_merge!(
|
|
51
|
-
reconnect_attempts: 1,
|
|
52
|
-
reconnect_delay: 0.2,
|
|
53
|
-
)
|
|
54
|
-
end
|
|
55
|
-
args[:url] ||= ENV['REDIS_URL'] unless args.key?(:redis) || args.key?(:url)
|
|
41
|
+
args[:pool] ||= {}
|
|
42
|
+
args[:pool][:size] ||= Integer(ENV.fetch('RAILS_MAX_THREADS'){ 5 })
|
|
43
|
+
args[:url] ||= ENV['REDIS_URL'] unless args.key?(:client) || args.key?(:url)
|
|
56
44
|
args[:url] = args[:url].split(',') if args[:url].is_a?(String)
|
|
57
45
|
super(**args)
|
|
58
46
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smart_cache_store
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0.rc1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thomas morgan
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: activesupport
|
|
@@ -16,30 +15,30 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - ">="
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
18
|
+
version: 8.2.0.a
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
25
|
+
version: 8.2.0.a
|
|
27
26
|
- !ruby/object:Gem::Dependency
|
|
28
27
|
name: connection_pool
|
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
|
30
29
|
requirements:
|
|
31
|
-
- - "
|
|
30
|
+
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
32
|
+
version: '3'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
39
|
+
version: '3'
|
|
41
40
|
description: Production-ready enhancements for mem_cache_store and redis_cache_store.
|
|
42
|
-
|
|
41
|
+
Works with Memcache, Redis, Valkey, and compatible. Use with Rails or just ActiveSupport.
|
|
43
42
|
email:
|
|
44
43
|
- tm@iprog.com
|
|
45
44
|
executables: []
|
|
@@ -59,8 +58,8 @@ licenses:
|
|
|
59
58
|
- MIT
|
|
60
59
|
metadata:
|
|
61
60
|
homepage_uri: https://github.com/zarqman/smart_cache_store
|
|
61
|
+
source_code_uri: https://github.com/zarqman/smart_cache_store
|
|
62
62
|
changelog_uri: https://github.com/zarqman/smart_cache_store/blob/master/CHANGELOG.md
|
|
63
|
-
post_install_message:
|
|
64
63
|
rdoc_options: []
|
|
65
64
|
require_paths:
|
|
66
65
|
- lib
|
|
@@ -68,15 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
68
67
|
requirements:
|
|
69
68
|
- - ">="
|
|
70
69
|
- !ruby/object:Gem::Version
|
|
71
|
-
version:
|
|
70
|
+
version: 3.3.1
|
|
72
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
72
|
requirements:
|
|
74
73
|
- - ">="
|
|
75
74
|
- !ruby/object:Gem::Version
|
|
76
75
|
version: '0'
|
|
77
76
|
requirements: []
|
|
78
|
-
rubygems_version:
|
|
79
|
-
signing_key:
|
|
77
|
+
rubygems_version: 4.0.16
|
|
80
78
|
specification_version: 4
|
|
81
79
|
summary: Production-ready enhancements for mem_cache_store and redis_cache_store
|
|
82
80
|
test_files: []
|