legion-cache 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dab39061de216282a220ec038a80444f3a77238100dc1d6b6ac9ecdf97d0903f
4
+ data.tar.gz: 5a2ec7633c66a15c34251051c31d12c38ad5a38b7853b1ba51d099a4b88c39a7
5
+ SHA512:
6
+ metadata.gz: 033b9f8f9dcc1d14b505161207d690481490dbb329a64b9d80078371fafe17d2955479bf3d2e592369803268448f7200f6cd5e9f4151a34b8afc230ca5c8da4b
7
+ data.tar.gz: '0958bf77c95cd1d7857d384fc3e567dd191b04b294bb8a40865ab7dd7afe752697e6afe8b5fcb93140e168b677300ac5092cdb4529d938a22c5954b9c5768be2'
@@ -0,0 +1,61 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.2.1
4
+
5
+ jobs:
6
+ "rubocop":
7
+ docker:
8
+ - image: circleci/ruby:2.5-node
9
+ steps:
10
+ - checkout
11
+ - ruby/load-cache
12
+ - ruby/install-deps
13
+ - run:
14
+ name: Run Rubocop
15
+ command: bundle exec rubocop
16
+ - ruby/save-cache
17
+ "ruby-two-five":
18
+ docker:
19
+ - image: circleci/ruby:2.5
20
+ - image: memcached:1.5-alpine
21
+ steps:
22
+ - checkout
23
+ - ruby/load-cache
24
+ - ruby/install-deps
25
+ - ruby/run-tests
26
+ - ruby/save-cache
27
+ "ruby-two-six":
28
+ docker:
29
+ - image: circleci/ruby:2.6
30
+ - image: memcached:1.5-alpine
31
+ steps:
32
+ - checkout
33
+ - ruby/load-cache
34
+ - ruby/install-deps
35
+ - ruby/run-tests
36
+ - ruby/save-cache
37
+ "ruby-two-seven":
38
+ docker:
39
+ - image: circleci/ruby:2.7
40
+ - image: memcached:1.5-alpine
41
+ steps:
42
+ - checkout
43
+ - ruby/load-cache
44
+ - ruby/install-deps
45
+ - ruby/run-tests
46
+ - ruby/save-cache
47
+
48
+ workflows:
49
+ version: 2
50
+ rubocop-rspec:
51
+ jobs:
52
+ - rubocop
53
+ - ruby-two-five:
54
+ requires:
55
+ - rubocop
56
+ - ruby-two-six:
57
+ requires:
58
+ - ruby-two-five
59
+ - ruby-two-seven:
60
+ requires:
61
+ - ruby-two-five
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,23 @@
1
+ Layout/LineLength:
2
+ Max: 120
3
+ Metrics/MethodLength:
4
+ Max: 30
5
+ Metrics/ClassLength:
6
+ Max: 1500
7
+ Metrics/BlockLength:
8
+ Max: 50
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+ Style/SymbolArray:
12
+ Enabled: true
13
+ Layout/HashAlignment:
14
+ EnforcedHashRocketStyle: table
15
+ EnforcedColonStyle: table
16
+ Style/Documentation:
17
+ Enabled: false
18
+ AllCops:
19
+ TargetRubyVersion: 2.5
20
+ Style/FrozenStringLiteralComment:
21
+ Enabled: false
22
+ Naming/FileName:
23
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in legion-cache.gemspec
6
+ gemspec
7
+
8
+ gem 'legion-settings', path: '~/legion-io/legion-settings'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Esity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Legion::Cache
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/legion/cache`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'legion-cache'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install legion-cache
20
+
21
+ ## Usage
22
+
23
+
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://bitbucket.org/legion-io/legion-cache/issues
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'legion/cache'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/cache/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'legion-cache'
7
+ spec.version = Legion::Cache::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'Legion::Cache integration'
12
+ spec.description = 'Used to connect Legion with a cache service like memcached'
13
+ spec.homepage = 'https://bitbucket.org/legion-io/legion-cache'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/legion-cache/src'
19
+ spec.metadata['changelog_uri'] = 'https://bitbucket.org/legion-io/legion-cache/src/master/CHANGELOG.md'
20
+ spec.metadata['wiki_uri'] = 'https://bitbucket.org/legion-io/legion-cache/wiki'
21
+ spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/legion-cache/issues'
22
+
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler'
31
+ spec.add_development_dependency 'legion-logging'
32
+ spec.add_development_dependency 'legion-settings'
33
+ spec.add_development_dependency 'rake'
34
+ spec.add_development_dependency 'rspec'
35
+ spec.add_development_dependency 'rspec_junit_formatter'
36
+ spec.add_development_dependency 'rubocop'
37
+ spec.add_development_dependency 'simplecov'
38
+
39
+ spec.add_dependency 'connection_pool'
40
+ spec.add_dependency 'dalli'
41
+ spec.add_dependency 'redis'
42
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'cache/version'
2
+ require_relative 'cache/settings'
3
+
4
+ require_relative 'cache/memcached'
5
+ require_relative 'cache/redis'
6
+
7
+ module Legion
8
+ module Cache
9
+ class << self
10
+ attr_reader :client
11
+ include Legion::Cache::Memcached if Legion::Settings[:cache][:driver] == 'dalli'
12
+ include Legion::Cache::Redis if Legion::Settings[:cache][:driver] == 'redis'
13
+
14
+ def setup
15
+ connect
16
+ Legion::Logging.info 'Legion::Cache connected and enabled'
17
+ end
18
+
19
+ def shutdown
20
+ Legion::Logging.info 'Shutting down Legion::Cache'
21
+ close
22
+ Legion::Settings[:cache][:connected] = false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ require 'dalli'
2
+
3
+ module Legion
4
+ module Cache
5
+ module Memcached
6
+ def connect
7
+ Legion::Logging.debug 'Using Memcached module for Legion::Cache'
8
+ options = { compress: true,
9
+ serializer: Legion::JSON,
10
+ failover: Legion::Settings[:cache][:failover],
11
+ namespace: Legion::Settings[:cache][:namespace], foo: 'test' }
12
+ Dalli.logger = Legion::Logging
13
+ @client = Dalli::Client.new(Legion::Settings[:cache][:servers], options)
14
+ Legion::Logging.debug "Legion::Cache successfully connected to #{Legion::Settings[:cache][:servers]}"
15
+ Legion::Settings[:cache][:connected] = true
16
+ end
17
+
18
+ def close
19
+ @client.close
20
+ end
21
+
22
+ def restart
23
+ close
24
+ connect
25
+ end
26
+
27
+ def get(key)
28
+ @client.get(key)
29
+ end
30
+
31
+ def fetch(key, ttl = nil)
32
+ @client.fetch(key, ttl)
33
+ end
34
+
35
+ def set(key, value, ttl = 180)
36
+ @client.set(key, value, ttl)
37
+ end
38
+
39
+ def delete(key)
40
+ @client.delete(key)
41
+ end
42
+
43
+ def flush(delay = 0)
44
+ @client.flush(delay)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ require 'redis'
2
+
3
+ module Legion
4
+ module Cache
5
+ module Redis
6
+ def connect
7
+ @client = Redis.new
8
+ end
9
+
10
+ def close
11
+ @client.close
12
+ end
13
+
14
+ def restart
15
+ close
16
+ connect
17
+ end
18
+
19
+ def get(key)
20
+ @client[key]
21
+ end
22
+
23
+ def set(key, value)
24
+ @client[key] = value
25
+ end
26
+
27
+ def delete(key)
28
+ @client.del key
29
+ end
30
+
31
+ def flush
32
+ @client.flushdb
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module Legion
2
+ module Cache
3
+ module Settings
4
+ def self.default
5
+ {
6
+ driver: 'dalli',
7
+ servers: ['127.0.0.1:11211'],
8
+ connected: false,
9
+ enabled: true,
10
+ namespace: 'legion',
11
+ compress: false,
12
+ failover: true,
13
+ threadsafe: true,
14
+ expires_in: 0,
15
+ cache_nils: false,
16
+ pool_size: 1,
17
+ serializer: Legion::JSON
18
+ }
19
+ end
20
+
21
+ def self.driver
22
+ if Gem::Specification.find_by_name('dalli')
23
+ 'dalli'
24
+ elsif Gem::Specification.find_by_name('redis')
25
+ 'redis'
26
+ else
27
+ raise NameError('Legion::Cache.driver is nil')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Cache
5
+ VERSION = '0.2.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: legion-cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: legion-logging
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: legion-settings
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec_junit_formatter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: connection_pool
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: dalli
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: redis
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Used to connect Legion with a cache service like memcached
168
+ email:
169
+ - matthewdiverson@gmail.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".circleci/config.yml"
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".rubocop.yml"
178
+ - Gemfile
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/setup
184
+ - legion-cache.gemspec
185
+ - lib/legion/cache.rb
186
+ - lib/legion/cache/memcached.rb
187
+ - lib/legion/cache/redis.rb
188
+ - lib/legion/cache/settings.rb
189
+ - lib/legion/cache/version.rb
190
+ homepage: https://bitbucket.org/legion-io/legion-cache
191
+ licenses:
192
+ - MIT
193
+ metadata:
194
+ homepage_uri: https://bitbucket.org/legion-io/legion-cache
195
+ source_code_uri: https://bitbucket.org/legion-io/legion-cache/src
196
+ changelog_uri: https://bitbucket.org/legion-io/legion-cache/src/master/CHANGELOG.md
197
+ wiki_uri: https://bitbucket.org/legion-io/legion-cache/wiki
198
+ bug_tracker_uri: https://bitbucket.org/legion-io/legion-cache/issues
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: 2.5.0
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubygems_version: 3.0.3
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: Legion::Cache integration
218
+ test_files: []