caddy 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 557e6259f9f172bdaf516e829bb169d8a89663f9
4
+ data.tar.gz: 0f36ca38a97ff49e466d97206823e1ad78c1e34b
5
+ SHA512:
6
+ metadata.gz: b54cbcab570b82c83f97d7e78823ee6affa185cfb8ec1f6edf9d81c6fd8ec01454266cdc496cbea6c656f8acf545c5b2e05ac1122eff5fcedd0805c5ef1468e6
7
+ data.tar.gz: 0a6b074bb61328edbd8ee7bfc05e94ab2fcca3d75f64b2e1a1cb5f44a981780e16f7b77fee5df06a707d3b38f92e7151c2c150f0de8d5ec5aaeb43c04dc00e94
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,219 @@
1
+ AllCops:
2
+ Exclude:
3
+ - .git/**/*
4
+ - tmp/**/*
5
+ - suo.gemspec
6
+
7
+ Lint/DuplicateMethods:
8
+ Enabled: true
9
+
10
+ Lint/DeprecatedClassMethods:
11
+ Enabled: true
12
+
13
+ Style/TrailingWhitespace:
14
+ Enabled: true
15
+
16
+ Style/Tab:
17
+ Enabled: true
18
+
19
+ Style/TrailingBlankLines:
20
+ Enabled: true
21
+
22
+ Style/NilComparison:
23
+ Enabled: true
24
+
25
+ Style/NonNilCheck:
26
+ Enabled: true
27
+
28
+ Style/Not:
29
+ Enabled: true
30
+
31
+ Style/RedundantReturn:
32
+ Enabled: true
33
+
34
+ Style/ClassCheck:
35
+ Enabled: true
36
+
37
+ Style/EmptyLines:
38
+ Enabled: true
39
+
40
+ Style/EmptyLiteral:
41
+ Enabled: true
42
+
43
+ Style/Alias:
44
+ Enabled: true
45
+
46
+ Style/MethodCallParentheses:
47
+ Enabled: true
48
+
49
+ Style/MethodDefParentheses:
50
+ Enabled: true
51
+
52
+ Style/SpaceBeforeBlockBraces:
53
+ Enabled: true
54
+
55
+ Style/SpaceInsideBlockBraces:
56
+ Enabled: true
57
+
58
+ Style/SpaceInsideParens:
59
+ Enabled: true
60
+
61
+ Style/DeprecatedHashMethods:
62
+ Enabled: true
63
+
64
+ Style/HashSyntax:
65
+ Enabled: true
66
+
67
+ Style/SpaceInsideHashLiteralBraces:
68
+ Enabled: true
69
+ EnforcedStyle: no_space
70
+
71
+ Style/SpaceInsideBrackets:
72
+ Enabled: true
73
+
74
+ Style/AndOr:
75
+ Enabled: false
76
+
77
+ Style/TrailingCommaInLiteral:
78
+ Enabled: true
79
+
80
+ Style/SpaceBeforeComma:
81
+ Enabled: true
82
+
83
+ Style/SpaceBeforeComment:
84
+ Enabled: true
85
+
86
+ Style/SpaceBeforeSemicolon:
87
+ Enabled: true
88
+
89
+ Style/SpaceAroundBlockParameters:
90
+ Enabled: true
91
+
92
+ Style/SpaceAroundOperators:
93
+ Enabled: true
94
+
95
+ Style/SpaceAfterColon:
96
+ Enabled: true
97
+
98
+ Style/SpaceAfterComma:
99
+ Enabled: true
100
+
101
+ Style/SpaceAroundKeyword:
102
+ Enabled: true
103
+
104
+ Style/SpaceAfterNot:
105
+ Enabled: true
106
+
107
+ Style/SpaceAfterSemicolon:
108
+ Enabled: true
109
+
110
+ Lint/UselessComparison:
111
+ Enabled: true
112
+
113
+ Lint/InvalidCharacterLiteral:
114
+ Enabled: true
115
+
116
+ Lint/LiteralInInterpolation:
117
+ Enabled: true
118
+
119
+ Lint/LiteralInCondition:
120
+ Enabled: true
121
+
122
+ Lint/UnusedBlockArgument:
123
+ Enabled: true
124
+
125
+ Style/VariableInterpolation:
126
+ Enabled: true
127
+
128
+ Style/RedundantSelf:
129
+ Enabled: true
130
+
131
+ Style/ParenthesesAroundCondition:
132
+ Enabled: true
133
+
134
+ Style/WhileUntilDo:
135
+ Enabled: true
136
+
137
+ Style/EmptyLineBetweenDefs:
138
+ Enabled: true
139
+
140
+ Style/EmptyLinesAroundAccessModifier:
141
+ Enabled: true
142
+
143
+ Style/EmptyLinesAroundMethodBody:
144
+ Enabled: true
145
+
146
+ Style/ColonMethodCall:
147
+ Enabled: true
148
+
149
+ Lint/SpaceBeforeFirstArg:
150
+ Enabled: true
151
+
152
+ Lint/UnreachableCode:
153
+ Enabled: true
154
+
155
+ Style/UnlessElse:
156
+ Enabled: true
157
+
158
+ Style/ClassVars:
159
+ Enabled: true
160
+
161
+ Style/StringLiterals:
162
+ Enabled: true
163
+ EnforcedStyle: double_quotes
164
+
165
+ Metrics/CyclomaticComplexity:
166
+ Max: 10
167
+
168
+ Metrics/LineLength:
169
+ Max: 128
170
+
171
+ Metrics/MethodLength:
172
+ Max: 32
173
+
174
+ Metrics/PerceivedComplexity:
175
+ Max: 8
176
+
177
+ # Disabled
178
+
179
+ Style/EvenOdd:
180
+ Enabled: false
181
+
182
+ Style/AsciiComments:
183
+ Enabled: false
184
+
185
+ Style/NumericLiterals:
186
+ Enabled: false
187
+
188
+ Style/UnneededPercentQ:
189
+ Enabled: false
190
+
191
+ Style/SpecialGlobalVars:
192
+ Enabled: false
193
+
194
+ Style/TrivialAccessors:
195
+ Enabled: false
196
+
197
+ Style/PerlBackrefs:
198
+ Enabled: false
199
+
200
+ Metrics/AbcSize:
201
+ Enabled: false
202
+
203
+ Metrics/BlockNesting:
204
+ Enabled: false
205
+
206
+ Metrics/ClassLength:
207
+ Enabled: false
208
+
209
+ Metrics/MethodLength:
210
+ Enabled: false
211
+
212
+ Metrics/ParameterLists:
213
+ Enabled: false
214
+
215
+ Metrics/PerceivedComplexity:
216
+ Enabled: false
217
+
218
+ Style/Documentation:
219
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.2.0
7
+ - 2.3.0
8
+ - ruby-head
9
+ - jruby-head
10
+ matrix:
11
+ allow_failures:
12
+ - rvm: ruby-head
13
+ - rvm: jruby-head
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Nick Elser
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Caddy (WORK IN PROGRESS)
2
+
3
+ Holds your stuff, and keeps it up to date.
4
+
5
+ ```ruby
6
+ # in your initializers (caddy.rb would be a wonderful name)
7
+ Caddy.refresher = -> { Hash[SomeKeyValueModel.all.map { |skvm| [skvm.key.to_sym, skvm.value } }
8
+ Caddy.refresh_interval = 5.minutes # default is 60 seconds
9
+
10
+ # ... in your unicorn.rb/puma.rb after fork/start
11
+ Caddy.start
12
+
13
+ # ... in a controller
14
+ def index
15
+ # the Caddy requests are instant, and are up-to-date (as of 5 minutes ago, as specified above)
16
+ # you could use this for high-level feature flags, cache dumping
17
+ if Caddy[:use_the_fast_index]
18
+ Rails.cache.fetch("#{Caddy[:global_cache_version}/#{Caddy[:foo_index_cache_version}/foo/bar") do
19
+ # wonderful things happen here
20
+ end
21
+ end
22
+ end
23
+ ```
24
+
25
+ ## Give it to me!
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem "caddy"
31
+ ```
32
+
33
+ ## Semantic Versioning
34
+
35
+ This project conforms to [semver](http://semver.org/). As a result of this
36
+ policy, you can (and should) specify a dependency on this gem using the
37
+ [Pessimistic Version Constraint](http://guides.rubygems.org/patterns/) with
38
+ two digits of precision. For example:
39
+
40
+ ```ruby
41
+ spec.add_dependency "caddy", "~> 1.0"
42
+ ```
43
+
44
+ This means your project is compatible with caddy 1.0 up until 2.0.
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
53
+
54
+ Don't forget to run the tests with `rake`.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task default: :test
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
+ end
data/caddy.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "caddy/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "caddy"
8
+ s.version = Caddy::VERSION
9
+ s.authors = ["Nick Elser"]
10
+ s.email = ["nick.elser@gmail.com"]
11
+ s.description = %q{Caddy gives you a magical auto-updating global cache.}
12
+ s.summary = %q{Caddy gives you a magical auto-updating global cache.}
13
+ s.homepage = "http://github.com/nickelser/caddy"
14
+ s.licenses = ["MIT"]
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "concurrent-ruby"
22
+
23
+ s.add_development_dependency "rake", "~> 10.5"
24
+ s.add_development_dependency "minitest", "~> 5.0"
25
+ end
data/lib/caddy.rb ADDED
@@ -0,0 +1,66 @@
1
+ require "caddy/version"
2
+ require "concurrent/timer_task"
3
+
4
+ module Caddy
5
+ class << self
6
+ attr_accessor :refresher
7
+ attr_writer :refresh_interval
8
+ end
9
+
10
+ DEFAULT_REFRESH_INTERVAL = 60
11
+ REFRESH_INTERVAL_JITTER_PCT = 0.1
12
+ DEFAULT_INITIAL_VALUE_WAIT = 0.1
13
+
14
+ def self.[](k)
15
+ raise "Please run `Caddy.start` before attempting to access values" unless @task
16
+ raise "Caddy variable access before initial load; allow some more time for your system to warm up" unless @task.value
17
+ @task.value[k]
18
+ end
19
+
20
+ def self.start
21
+ unless refresher
22
+ raise "Please set your cache refresher via `Caddy.refresher = -> { <code that returns a value> }`"
23
+ end
24
+
25
+ if @task
26
+ puts "Caddy already running; shutting it down and starting over. Please ensure you run `Caddy.start`"\
27
+ " only after fork/worker start in your web processes."
28
+ @task.shutdown
29
+ end
30
+
31
+ jitter_amount = refresh_interval * REFRESH_INTERVAL_JITTER_PCT
32
+ interval = refresh_interval + rand(-jitter_amount...jitter_amount)
33
+
34
+ @task = Concurrent::TimerTask.new(
35
+ run_now: true,
36
+ freeze_on_deref: true,
37
+ execution_interval: interval,
38
+ timeout_interval: interval - 1) { refresher.call }
39
+
40
+ @task.add_observer(CaddyTaskObserver.new)
41
+ @task.execute
42
+ end
43
+
44
+ def self.stop
45
+ raise "Please run `Caddy.start` before running `Caddy.stop`" unless @task
46
+
47
+ @task.shutdown
48
+ @task = nil
49
+ end
50
+
51
+ def self.refresh_interval
52
+ @refresh_interval || DEFAULT_REFRESH_INTERVAL
53
+ end
54
+
55
+ class CaddyTaskObserver
56
+ def update(time, _, boom)
57
+ return unless boom
58
+
59
+ if boom.is_a?(Concurrent::TimeoutError)
60
+ puts "(#{time}) Caddy refresher timed out"
61
+ else
62
+ puts "(#{time}) Caddy refresher failed with error #{boom}"
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module Caddy
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "minitest/autorun"
2
+ require "caddy"
3
+
4
+ class CaddyTest < Minitest::Test
5
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: caddy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Elser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: concurrent-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Caddy gives you a magical auto-updating global cache.
56
+ email:
57
+ - nick.elser@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rubocop.yml"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - caddy.gemspec
70
+ - lib/caddy.rb
71
+ - lib/caddy/version.rb
72
+ - test/caddy_test.rb
73
+ homepage: http://github.com/nickelser/caddy
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.5.1
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Caddy gives you a magical auto-updating global cache.
97
+ test_files:
98
+ - test/caddy_test.rb
99
+ has_rdoc: