legion-cache 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a0e98b3a109f9afe974174f40b6e881b1bc0fc44d8425170414cea1bd035f80
4
- data.tar.gz: 533023b2a19842e481108e8954e4085cb7a38c6773fd4d87482257791bce90bb
3
+ metadata.gz: c084b2a826a462326ca3f8e76caadf7a7e37a78760cf5dbeb67b5ec99fe8a0ae
4
+ data.tar.gz: c841a6cb5586e091fedbad0d16b414127596943009a2dccb90fdf45f4a15e0c4
5
5
  SHA512:
6
- metadata.gz: 202568edde877bd7a9e2c0e5b245e4283f818dfbb8118a316e9fbf145ca853910c2e1da44145cc6c71698846d7d62d391495fa965708d30063bce304d4519263
7
- data.tar.gz: fbf7bfaa69f0d5f79e11d56b877481220a267d94775aeb2bcb8d243ab0baa49ecc18c6d6715ac18f5933ff3d7553ef232492c42528af548ffc264ef2d64c0c46
6
+ metadata.gz: 2ff55af73c6deb78556832331872bac6e89342d4fc0c40efd711ebc66731cb3d2b99316c1a9e0d043afcced6bf222c9d9e43a24379735fea7872839be256b88e
7
+ data.tar.gz: 77d8df72f0c1dcd555b491b037674fc090c1bd8e390e22a49b66c1ab9663b975505c0bc637557b7550603cc62f5e0bb25000c8fbe3de02b377e636294181ac97
@@ -6,6 +6,10 @@ Metrics/ClassLength:
6
6
  Max: 1500
7
7
  Metrics/BlockLength:
8
8
  Max: 50
9
+ Exclude:
10
+ - 'spec/*/**.rb'
11
+ Metrics/AbcSize:
12
+ Max: 20
9
13
  Layout/SpaceAroundEqualsInParameterDefault:
10
14
  EnforcedStyle: space
11
15
  Style/SymbolArray:
@@ -1,64 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- legion-cache (1.0.0)
5
- connection_pool
6
- dalli
7
- redis
4
+ legion-cache (1.1.0)
5
+ connection_pool (>= 2.2.3)
6
+ dalli (>= 2.7)
7
+ redis (>= 4.2)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.1)
13
13
  connection_pool (2.2.3)
14
- dalli (2.7.10)
14
+ dalli (2.7.11)
15
15
  diff-lcs (1.4.4)
16
16
  docile (1.3.2)
17
17
  json (2.3.1)
18
- legion-json (1.1.0)
18
+ json_pure (2.3.1)
19
+ legion-json (1.1.2)
20
+ json_pure
19
21
  multi_json
20
- legion-logging (1.1.0)
22
+ legion-logging (1.1.3)
21
23
  rainbow (~> 3)
22
- legion-settings (1.1.0)
24
+ legion-settings (1.1.2)
23
25
  legion-json
24
26
  legion-logging
25
27
  multi_json (1.15.0)
26
28
  parallel (1.19.2)
27
- parser (2.7.1.4)
29
+ parser (2.7.2.0)
28
30
  ast (~> 2.4.1)
29
31
  rainbow (3.0.0)
30
32
  rake (13.0.1)
31
- redis (4.2.1)
32
- regexp_parser (1.7.1)
33
+ redis (4.2.2)
34
+ regexp_parser (1.8.2)
33
35
  rexml (3.2.4)
34
- rspec (3.9.0)
35
- rspec-core (~> 3.9.0)
36
- rspec-expectations (~> 3.9.0)
37
- rspec-mocks (~> 3.9.0)
38
- rspec-core (3.9.2)
39
- rspec-support (~> 3.9.3)
40
- rspec-expectations (3.9.2)
36
+ rspec (3.10.0)
37
+ rspec-core (~> 3.10.0)
38
+ rspec-expectations (~> 3.10.0)
39
+ rspec-mocks (~> 3.10.0)
40
+ rspec-core (3.10.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-expectations (3.10.0)
41
43
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.9.0)
43
- rspec-mocks (3.9.1)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-mocks (3.10.0)
44
46
  diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.9.0)
46
- rspec-support (3.9.3)
47
+ rspec-support (~> 3.10.0)
48
+ rspec-support (3.10.0)
47
49
  rspec_junit_formatter (0.4.1)
48
50
  rspec-core (>= 2, < 4, != 2.12.0)
49
- rubocop (0.88.0)
51
+ rubocop (1.2.0)
50
52
  parallel (~> 1.10)
51
- parser (>= 2.7.1.1)
53
+ parser (>= 2.7.1.5)
52
54
  rainbow (>= 2.2.2, < 4.0)
53
- regexp_parser (>= 1.7)
55
+ regexp_parser (>= 1.8)
54
56
  rexml
55
- rubocop-ast (>= 0.1.0, < 1.0)
57
+ rubocop-ast (>= 1.0.1)
56
58
  ruby-progressbar (~> 1.7)
57
59
  unicode-display_width (>= 1.4.0, < 2.0)
58
- rubocop-ast (0.2.0)
59
- parser (>= 2.7.0.1)
60
- rubocop-performance (1.7.1)
61
- rubocop (>= 0.82.0)
60
+ rubocop-ast (1.1.1)
61
+ parser (>= 2.7.1.5)
62
+ rubocop-performance (1.8.1)
63
+ rubocop (>= 0.87.0)
64
+ rubocop-ast (>= 0.4.0)
62
65
  ruby-progressbar (1.10.1)
63
66
  simplecov (0.17.1)
64
67
  docile (~> 1.1)
@@ -71,7 +74,7 @@ PLATFORMS
71
74
  ruby
72
75
 
73
76
  DEPENDENCIES
74
- bundler
77
+ bundler (>= 2)
75
78
  legion-cache!
76
79
  legion-logging
77
80
  legion-settings
@@ -0,0 +1,18 @@
1
+ image: ruby:2.7
2
+
3
+ pipelines:
4
+ tags:
5
+ "v*":
6
+ - step:
7
+ name: Push to RubyGems
8
+ deployment: RubyGems
9
+ script:
10
+ - gem install bundler gem-release rspec
11
+ - bundle install
12
+ - (umask 077 ; echo $gem_creds | base64 --decode > ~/.gem/credentials)
13
+ - gem release
14
+ artifacts:
15
+ - pkg/**
16
+ definitions:
17
+ caches:
18
+ bundler: /usr/local/bundle
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'bundler', '>= 2'
30
30
  spec.add_development_dependency 'legion-logging'
31
31
  spec.add_development_dependency 'legion-settings'
32
32
  spec.add_development_dependency 'rake'
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'rubocop-performance'
37
37
  spec.add_development_dependency 'simplecov', '< 0.18.0'
38
38
 
39
- spec.add_dependency 'connection_pool'
40
- spec.add_dependency 'dalli'
41
- spec.add_dependency 'redis'
39
+ spec.add_dependency 'connection_pool', '>= 2.2.3'
40
+ spec.add_dependency 'dalli', '>= 2.7'
41
+ spec.add_dependency 'redis', '>= 4.2'
42
42
  end
@@ -10,6 +10,15 @@ module Legion
10
10
  include Legion::Cache::Memcached if Legion::Settings[:cache][:driver] == 'dalli'
11
11
  include Legion::Cache::Redis if Legion::Settings[:cache][:driver] == 'redis'
12
12
 
13
+ def setup(**opts)
14
+ return Legion::Settings[:cache][:connected] = true if connected?
15
+
16
+ return unless client(**Legion::Settings[:cache], **opts)
17
+
18
+ @connected = true
19
+ Legion::Settings[:cache][:connected] = true
20
+ end
21
+
13
22
  def shutdown
14
23
  Legion::Logging.info 'Shutting down Legion::Cache'
15
24
  close
@@ -1,51 +1,45 @@
1
1
  require 'dalli'
2
+ require 'legion/cache/pool'
2
3
 
3
4
  module Legion
4
5
  module Cache
5
6
  module Memcached
7
+ include Legion::Cache::Pool
6
8
  extend self
7
9
 
8
10
  def client(servers: Legion::Settings[:cache][:servers], **opts)
9
11
  return @client unless @client.nil?
10
12
 
13
+ @pool_size = opts.key?(:pool_size) ? opts[:pool_size] : Legion::Settings[:cache][:pool_size] || 10
14
+ @timeout = opts.key?(:timeout) ? opts[:timeout] : Legion::Settings[:cache][:timeout] || 5
15
+
11
16
  Dalli.logger = Legion::Logging
12
- @client = Dalli::Client.new(servers, Legion::Settings[:cache].merge(opts))
17
+ @client = ConnectionPool.new(size: pool_size, timeout: timeout) do
18
+ Dalli::Client.new(servers, Legion::Settings[:cache].merge(opts))
19
+ end
20
+
13
21
  @connected = true
14
22
  @client
15
23
  end
16
24
 
17
- def connected?
18
- @connected ||= false
19
- end
20
-
21
- def close
22
- client.close
23
- end
24
-
25
- def restart
26
- close
27
- @client = nil
28
- client
29
- end
30
-
31
25
  def get(key)
32
- client.get(key)
26
+ client.with { |conn| conn.get(key) }
33
27
  end
34
28
 
35
29
  def fetch(key, ttl = nil)
36
- client.fetch(key, ttl)
30
+ client.with { |conn| conn.fetch(key, ttl) }
37
31
  end
38
32
 
39
33
  def set(key, value, ttl = 180)
40
- client.set(key, value, ttl).positive?
34
+ client.with { |conn| conn.set(key, value, ttl).positive? }
41
35
  end
42
36
 
43
37
  def delete(key)
44
- client.delete(key) == true
38
+ client.with { |conn| conn.delete(key) == true }
45
39
  end
46
40
 
47
41
  def flush(delay = 0)
48
- client.flush(delay).first
42
+ client.with { |conn| conn.flush(delay).first }
49
43
  end
50
44
  end
51
45
  end
@@ -0,0 +1,43 @@
1
+ require 'connection_pool'
2
+
3
+ module Legion
4
+ module Cache
5
+ module Pool
6
+ def connected?
7
+ @connected ||= false
8
+ end
9
+
10
+ def size
11
+ client.size
12
+ end
13
+
14
+ def timeout
15
+ @timeout ||= Legion::Settings[:cache][:timeout] || 5
16
+ end
17
+
18
+ def pool_size
19
+ @pool_size ||= Legion::Settings[:cache][:pool_size] || 10
20
+ end
21
+
22
+ def available
23
+ client.available
24
+ end
25
+
26
+ def close
27
+ client.shutdown(&:close)
28
+ @client = nil
29
+ @connected = false
30
+ end
31
+
32
+ def restart(**opts)
33
+ close
34
+ @client = nil
35
+ client_hash = opts
36
+ client_hash[:pool_size] = opts[:pool_size] if opts.key? :pool_size
37
+ client_hash[:timeout] = opts[:timeout] if opts.key? :timeout
38
+ client(**client_hash)
39
+ @connected = true
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,49 +1,42 @@
1
1
  require 'redis'
2
+ require 'legion/cache/pool'
2
3
 
3
4
  module Legion
4
5
  module Cache
5
6
  module Redis
7
+ include Legion::Cache::Pool
6
8
  extend self
7
9
 
8
- def client
10
+ def client(pool_size: 20, timeout: 5, **)
9
11
  return @client unless @client.nil?
10
12
 
11
- @client = ::Redis.new
13
+ @pool_size = pool_size
14
+ @timeout = timeout
15
+
16
+ @client = ConnectionPool.new(size: pool_size, timeout: timeout) do
17
+ ::Redis.new
18
+ end
12
19
  @connected = true
13
20
  @client
14
21
  end
15
22
 
16
- def connected?
17
- @connected ||= false
18
- end
19
-
20
- def close
21
- client.close
22
- end
23
-
24
- def restart
25
- close
26
- @client = nil
27
- client
28
- end
29
-
30
23
  def get(key)
31
- client.get(key)
24
+ client.with { |conn| conn.get(key) }
32
25
  end
33
26
  alias fetch get
34
27
 
35
28
  def set(key, value, ttl: nil)
36
29
  args = {}
37
30
  args[:ex] = ttl unless ttl.nil?
38
- client.set(key, value, **args) == 'OK'
31
+ client.with { |conn| conn.set(key, value, **args) == 'OK' }
39
32
  end
40
33
 
41
34
  def delete(key)
42
- client.del(key) == 1
35
+ client.with { |conn| conn.del(key) == 1 }
43
36
  end
44
37
 
45
38
  def flush
46
- client.flushdb == 'OK'
39
+ client.with { |conn| conn.flushdb == 'OK' }
47
40
  end
48
41
  end
49
42
  end
@@ -14,7 +14,8 @@ module Legion
14
14
  threadsafe: true,
15
15
  expires_in: 0,
16
16
  cache_nils: false,
17
- pool_size: 5,
17
+ pool_size: 10,
18
+ timeout: 5,
18
19
  serializer: Legion::JSON
19
20
  }
20
21
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module Cache
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: legion-logging
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -142,42 +142,42 @@ dependencies:
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: 2.2.3
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: 2.2.3
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: dalli
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: '2.7'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: '2.7'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: redis
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: '0'
173
+ version: '4.2'
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
- version: '0'
180
+ version: '4.2'
181
181
  description: Used to connect Legion with a cache service like memcached
182
182
  email:
183
183
  - matthewdiverson@gmail.com
@@ -194,9 +194,11 @@ files:
194
194
  - LICENSE.txt
195
195
  - README.md
196
196
  - Rakefile
197
+ - bitbucket-pipelines.yml
197
198
  - legion-cache.gemspec
198
199
  - lib/legion/cache.rb
199
200
  - lib/legion/cache/memcached.rb
201
+ - lib/legion/cache/pool.rb
200
202
  - lib/legion/cache/redis.rb
201
203
  - lib/legion/cache/settings.rb
202
204
  - lib/legion/cache/version.rb
@@ -210,7 +212,7 @@ metadata:
210
212
  changelog_uri: https://bitbucket.org/legion-io/legion-cache/src/master/CHANGELOG.md
211
213
  wiki_uri: https://bitbucket.org/legion-io/legion-cache/wiki
212
214
  bug_tracker_uri: https://bitbucket.org/legion-io/legion-cache/issues
213
- post_install_message:
215
+ post_install_message:
214
216
  rdoc_options: []
215
217
  require_paths:
216
218
  - lib
@@ -225,8 +227,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
227
  - !ruby/object:Gem::Version
226
228
  version: '0'
227
229
  requirements: []
228
- rubygems_version: 3.1.2
229
- signing_key:
230
+ rubygems_version: 3.1.4
231
+ signing_key:
230
232
  specification_version: 4
231
233
  summary: Legion::Cache integration
232
234
  test_files: []