async_cache 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.travis.yml +18 -0
- data/Gemfile +0 -5
- data/Gemfile.lock +42 -13
- data/async_cache.gemspec +8 -2
- data/lib/async_cache/store.rb +1 -0
- data/lib/async_cache/version.rb +1 -1
- data/spec/integration/store_spec.rb +65 -0
- data/spec/integration/support/config.rb +18 -0
- data/spec/integration/support/run_all.rb +15 -0
- data/spec/integration/support/sinatra.rb +23 -0
- data/spec/integration/support/version.txt +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/store_spec.rb +6 -0
- data/spec/workers/base_spec.rb +25 -0
- metadata +94 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 403da7156db830a1ce124c163bd01f76bbc8d74e
|
4
|
+
data.tar.gz: baaead5a8cdf2518c73e3d951620db13c5bf02e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2335c08328573320f258606f2d19a70a28bccc8328d3d3a8ce6ce576f079e76cb4b5d5931fb297837e6e95714bf44e4e8912681a355273486f1f38d9ec15d98
|
7
|
+
data.tar.gz: 73dd67211b1b431155dbbd35e89f824db065fb2bb80066f07eef86e908931f8db533bc94c7d195d4d7d8bada9e8e022f36f57791637a1f828028b15eafc9f6e6
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- '2.2.1'
|
6
|
+
- '2.2.3'
|
7
|
+
- '2.3.0'
|
8
|
+
|
9
|
+
services:
|
10
|
+
- redis-server
|
11
|
+
|
12
|
+
before_script:
|
13
|
+
- bundle exec ruby spec/integration/support/run_all.rb &
|
14
|
+
- sleep 2
|
15
|
+
|
16
|
+
script:
|
17
|
+
- bundle exec rspec --exclude-pattern "spec/integration/*"
|
18
|
+
- bundle exec rspec spec/integration
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
async_cache (1.0.
|
4
|
+
async_cache (1.0.1)
|
5
5
|
sourcify (~> 0.5.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -64,12 +64,16 @@ GEM
|
|
64
64
|
coderay (1.1.0)
|
65
65
|
connection_pool (2.2.0)
|
66
66
|
diff-lcs (1.2.5)
|
67
|
+
docile (1.1.5)
|
67
68
|
erubis (2.7.0)
|
68
69
|
file-tail (1.1.0)
|
69
70
|
tins (~> 1.0)
|
70
71
|
globalid (0.3.6)
|
71
72
|
activesupport (>= 4.1.0)
|
72
73
|
hitimes (1.2.3)
|
74
|
+
httparty (0.13.7)
|
75
|
+
json (~> 1.8)
|
76
|
+
multi_xml (>= 0.5.2)
|
73
77
|
i18n (0.7.0)
|
74
78
|
json (1.8.3)
|
75
79
|
loofah (2.0.3)
|
@@ -80,6 +84,8 @@ GEM
|
|
80
84
|
mime-types (2.6.2)
|
81
85
|
mini_portile (0.6.2)
|
82
86
|
minitest (5.8.2)
|
87
|
+
multi_json (1.11.2)
|
88
|
+
multi_xml (0.5.5)
|
83
89
|
nokogiri (1.6.6.2)
|
84
90
|
mini_portile (~> 0.6.0)
|
85
91
|
pry (0.10.1)
|
@@ -87,6 +93,8 @@ GEM
|
|
87
93
|
method_source (~> 0.8.1)
|
88
94
|
slop (~> 3.4)
|
89
95
|
rack (1.6.4)
|
96
|
+
rack-protection (1.5.3)
|
97
|
+
rack
|
90
98
|
rack-test (0.6.3)
|
91
99
|
rack (>= 1.0)
|
92
100
|
rails (4.2.4)
|
@@ -115,17 +123,26 @@ GEM
|
|
115
123
|
thor (>= 0.18.1, < 2.0)
|
116
124
|
rake (10.4.2)
|
117
125
|
redis (3.2.1)
|
126
|
+
redis-activesupport (4.1.5)
|
127
|
+
activesupport (>= 3, < 5)
|
128
|
+
redis-store (~> 1.1.0)
|
118
129
|
redis-namespace (1.5.2)
|
119
130
|
redis (~> 3.0, >= 3.0.4)
|
120
|
-
|
121
|
-
|
122
|
-
rspec
|
131
|
+
redis-store (1.1.7)
|
132
|
+
redis (>= 2.2)
|
133
|
+
rspec (3.4.0)
|
134
|
+
rspec-core (~> 3.4.0)
|
135
|
+
rspec-expectations (~> 3.4.0)
|
136
|
+
rspec-mocks (~> 3.4.0)
|
137
|
+
rspec-core (3.4.1)
|
138
|
+
rspec-support (~> 3.4.0)
|
139
|
+
rspec-expectations (3.4.0)
|
123
140
|
diff-lcs (>= 1.2.0, < 2.0)
|
124
|
-
rspec-support (~> 3.
|
125
|
-
rspec-mocks (3.
|
141
|
+
rspec-support (~> 3.4.0)
|
142
|
+
rspec-mocks (3.4.0)
|
126
143
|
diff-lcs (>= 1.2.0, < 2.0)
|
127
|
-
rspec-support (~> 3.
|
128
|
-
rspec-support (3.
|
144
|
+
rspec-support (~> 3.4.0)
|
145
|
+
rspec-support (3.4.1)
|
129
146
|
ruby2ruby (2.2.0)
|
130
147
|
ruby_parser (~> 3.1)
|
131
148
|
sexp_processor (~> 4.0)
|
@@ -138,6 +155,15 @@ GEM
|
|
138
155
|
json (~> 1.0)
|
139
156
|
redis (~> 3.2, >= 3.2.1)
|
140
157
|
redis-namespace (~> 1.5, >= 1.5.2)
|
158
|
+
simplecov (0.9.2)
|
159
|
+
docile (~> 1.1.0)
|
160
|
+
multi_json (~> 1.0)
|
161
|
+
simplecov-html (~> 0.9.0)
|
162
|
+
simplecov-html (0.9.0)
|
163
|
+
sinatra (1.4.6)
|
164
|
+
rack (~> 1.4)
|
165
|
+
rack-protection (~> 1.4)
|
166
|
+
tilt (>= 1.3, < 3)
|
141
167
|
slop (3.6.0)
|
142
168
|
sourcify (0.5.0)
|
143
169
|
file-tail (>= 1.0.5)
|
@@ -152,6 +178,7 @@ GEM
|
|
152
178
|
sprockets (>= 2.8, < 4.0)
|
153
179
|
thor (0.19.1)
|
154
180
|
thread_safe (0.3.5)
|
181
|
+
tilt (1.4.1)
|
155
182
|
timers (4.1.1)
|
156
183
|
hitimes
|
157
184
|
tins (1.8.1)
|
@@ -163,12 +190,14 @@ PLATFORMS
|
|
163
190
|
|
164
191
|
DEPENDENCIES
|
165
192
|
async_cache!
|
166
|
-
|
193
|
+
httparty (~> 0.13.7)
|
194
|
+
pry (~> 0.10.1)
|
167
195
|
rails (~> 4.2.4)
|
168
|
-
|
169
|
-
rspec
|
170
|
-
rspec-mocks (~> 3.2.1)
|
196
|
+
redis-activesupport (~> 4.1.5)
|
197
|
+
rspec (~> 3.4.0)
|
171
198
|
sidekiq (~> 3.5.2)
|
199
|
+
simplecov (~> 0.9.2)
|
200
|
+
sinatra (~> 1.4.6)
|
172
201
|
|
173
202
|
BUNDLED WITH
|
174
|
-
1.
|
203
|
+
1.11.2
|
data/async_cache.gemspec
CHANGED
@@ -15,8 +15,14 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.add_dependency 'sourcify', '~> 0.5.0'
|
17
17
|
|
18
|
-
s.add_development_dependency 'rails',
|
19
|
-
s.add_development_dependency 'sidekiq',
|
18
|
+
s.add_development_dependency 'rails', '~> 4.2.4'
|
19
|
+
s.add_development_dependency 'sidekiq', '~> 3.5.2'
|
20
|
+
s.add_development_dependency 'sinatra', '~> 1.4.6'
|
21
|
+
s.add_development_dependency 'rspec', '~> 3.4.0'
|
22
|
+
s.add_development_dependency 'pry', '~> 0.10.1'
|
23
|
+
s.add_development_dependency 'simplecov', '~> 0.9.2'
|
24
|
+
s.add_development_dependency 'redis-activesupport', '~> 4.1.5'
|
25
|
+
s.add_development_dependency 'httparty', '~> 0.13.7'
|
20
26
|
|
21
27
|
s.files = `git ls-files`.split("\n")
|
22
28
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
data/lib/async_cache/store.rb
CHANGED
@@ -109,6 +109,7 @@ module AsyncCache
|
|
109
109
|
next if argument.is_a? Numeric
|
110
110
|
next if argument.is_a? String
|
111
111
|
next if argument.is_a? Symbol
|
112
|
+
next if argument.is_a? Hash
|
112
113
|
|
113
114
|
raise ArgumentError, "Cannot send complex data for block argument #{index + 1}: #{argument.class.name}"
|
114
115
|
end
|
data/lib/async_cache/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
require_relative './support/config'
|
5
|
+
|
6
|
+
describe AsyncCache::Store do
|
7
|
+
context '#fetch' do
|
8
|
+
before(:all) do
|
9
|
+
unless File.exist? VERSION_PATH
|
10
|
+
raise "Version file #{VERSION_PATH} doesn't exist"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
# 'y' is the locator used in `support/sinatra.rb`.
|
16
|
+
Rails.cache.delete LOCATOR
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:each) do
|
20
|
+
sleep 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_endpoint
|
24
|
+
response = HTTParty.get 'http://localhost:4567'
|
25
|
+
expect(response.success?).to eq true
|
26
|
+
|
27
|
+
return response.body
|
28
|
+
end
|
29
|
+
|
30
|
+
def touch_version_file
|
31
|
+
FileUtils.touch VERSION_PATH
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'serves the fresh version if the cache is empty' do
|
35
|
+
get_endpoint
|
36
|
+
end
|
37
|
+
|
38
|
+
it "serves the old version if it's cached" do
|
39
|
+
body1 = get_endpoint
|
40
|
+
|
41
|
+
touch_version_file
|
42
|
+
|
43
|
+
body2 = get_endpoint
|
44
|
+
|
45
|
+
expect(body1).to eq body2
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'serves the new version after the worker has run' do
|
49
|
+
body1 = get_endpoint
|
50
|
+
|
51
|
+
touch_version_file
|
52
|
+
|
53
|
+
body2 = get_endpoint
|
54
|
+
|
55
|
+
# Check again that it served the old version
|
56
|
+
expect(body2).to eq body1
|
57
|
+
|
58
|
+
sleep 0.5 # Give the worker a chance to run
|
59
|
+
|
60
|
+
body3 = get_endpoint
|
61
|
+
# Check that it served the new version after the worker ran
|
62
|
+
expect(body3).not_to eq body1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
require 'async_cache'
|
3
|
+
require 'async_cache/workers/sidekiq'
|
4
|
+
require 'rails'
|
5
|
+
require 'redis-activesupport'
|
6
|
+
|
7
|
+
Rails.cache = ActiveSupport::Cache::RedisStore.new
|
8
|
+
Rails.logger = Logger.new($stdout).tap { |log| log.level = Logger::WARN }
|
9
|
+
|
10
|
+
Sidekiq.configure_client do |config|
|
11
|
+
config.redis = { :namespace => 'x', :size => 1 }
|
12
|
+
end
|
13
|
+
Sidekiq.configure_server do |config|
|
14
|
+
config.redis = { :namespace => 'x' }
|
15
|
+
end
|
16
|
+
|
17
|
+
LOCATOR = 'y'
|
18
|
+
VERSION_PATH = File.join(File.dirname(__FILE__), 'version.txt')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
commands = [
|
4
|
+
'bundle exec sidekiq -c 2 -r ./spec/integration/support/config.rb',
|
5
|
+
'bundle exec ruby spec/integration/support/sinatra.rb'
|
6
|
+
]
|
7
|
+
|
8
|
+
pids = commands.map { |c| Process.spawn c }
|
9
|
+
|
10
|
+
shutdown = proc { Process.kill 'TERM', *pids }
|
11
|
+
|
12
|
+
Signal.trap 'INT', &shutdown
|
13
|
+
Signal.trap 'TERM', &shutdown
|
14
|
+
|
15
|
+
Process.waitall
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
require_relative './config'
|
5
|
+
|
6
|
+
store = nil
|
7
|
+
|
8
|
+
configure do
|
9
|
+
store = AsyncCache::Store.new worker: :sidekiq
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_file_version(path)
|
13
|
+
File.mtime(path).to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/' do
|
17
|
+
locator = LOCATOR
|
18
|
+
version = get_file_version VERSION_PATH
|
19
|
+
|
20
|
+
store.fetch(locator, version) do
|
21
|
+
SecureRandom.uuid
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -3,8 +3,11 @@ require 'bundler/setup'
|
|
3
3
|
require 'rails'
|
4
4
|
require 'sidekiq'
|
5
5
|
require 'sidekiq/testing'
|
6
|
+
require 'simplecov'
|
6
7
|
|
7
8
|
Sidekiq::Testing.inline!
|
9
|
+
SimpleCov.start
|
10
|
+
|
8
11
|
Rails.cache = ActiveSupport::Cache::MemoryStore.new
|
9
12
|
Rails.logger = Logger.new($stdout).tap { |log| log.level = Logger::ERROR }
|
10
13
|
|
data/spec/store_spec.rb
CHANGED
@@ -10,6 +10,12 @@ describe AsyncCache::Store do
|
|
10
10
|
)
|
11
11
|
end
|
12
12
|
|
13
|
+
it "raises if it doesn't receive a worker class" do
|
14
|
+
expect {
|
15
|
+
AsyncCache::Store.new backend: Rails.cache
|
16
|
+
}.to raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
|
13
19
|
context 'caching' do
|
14
20
|
def stub_not_present(key)
|
15
21
|
expect(Rails.cache).to receive(:read).with(key).and_return(nil)
|
data/spec/workers/base_spec.rb
CHANGED
@@ -14,4 +14,29 @@ describe AsyncCache::Workers do
|
|
14
14
|
expect(subject.worker_for_name :active_job).to eql AsyncCache::Workers::ActiveJobWorker
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
describe '#perform' do
|
19
|
+
class TestWorker
|
20
|
+
include AsyncCache::Workers::Base
|
21
|
+
end
|
22
|
+
|
23
|
+
subject do
|
24
|
+
TestWorker.new
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'evaluates the job and writes to the backend' do
|
28
|
+
backend = spy 'Backend'
|
29
|
+
allow(AsyncCache).to receive(:backend).and_return(backend)
|
30
|
+
|
31
|
+
key = 'test'
|
32
|
+
version = 42
|
33
|
+
expires_in = 1337
|
34
|
+
block_arguments = [1]
|
35
|
+
block_source = 'proc { |arg| arg * 2 }'
|
36
|
+
|
37
|
+
expect(backend).to receive(:write).with(key, [2, version], expires_in: expires_in)
|
38
|
+
|
39
|
+
subject.perform key, version, expires_in, block_arguments, block_source
|
40
|
+
end
|
41
|
+
end
|
17
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Derewecki
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sourcify
|
@@ -53,6 +53,90 @@ dependencies:
|
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: 3.5.2
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: sinatra
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.4.6
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.4.6
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 3.4.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 3.4.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: pry
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.10.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.10.1
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: simplecov
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.9.2
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.9.2
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: redis-activesupport
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 4.1.5
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 4.1.5
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: httparty
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.13.7
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 0.13.7
|
56
140
|
description:
|
57
141
|
email:
|
58
142
|
- derewecki@gmail.com
|
@@ -62,6 +146,8 @@ extensions: []
|
|
62
146
|
extra_rdoc_files: []
|
63
147
|
files:
|
64
148
|
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- ".travis.yml"
|
65
151
|
- Gemfile
|
66
152
|
- Gemfile.lock
|
67
153
|
- LICENSE
|
@@ -75,6 +161,11 @@ files:
|
|
75
161
|
- lib/async_cache/workers/active_job.rb
|
76
162
|
- lib/async_cache/workers/base.rb
|
77
163
|
- lib/async_cache/workers/sidekiq.rb
|
164
|
+
- spec/integration/store_spec.rb
|
165
|
+
- spec/integration/support/config.rb
|
166
|
+
- spec/integration/support/run_all.rb
|
167
|
+
- spec/integration/support/sinatra.rb
|
168
|
+
- spec/integration/support/version.txt
|
78
169
|
- spec/spec_helper.rb
|
79
170
|
- spec/store_spec.rb
|
80
171
|
- spec/workers/active_job_spec.rb
|
@@ -100,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
191
|
version: '0'
|
101
192
|
requirements: []
|
102
193
|
rubyforge_project:
|
103
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.5.1
|
104
195
|
signing_key:
|
105
196
|
specification_version: 4
|
106
197
|
summary: Pattern and library for implementing asynchronous caching
|