infopark_component_cache 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rubocop.yml +25 -0
- data/.rubocop_todo.yml +115 -0
- data/.travis.yml +24 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +206 -0
- data/Gemfile.rails51 +6 -0
- data/Gemfile.rails51.lock +206 -0
- data/Rakefile +7 -7
- data/app/helpers/infopark_component_cache_helper.rb +2 -2
- data/infopark_component_cache.gemspec +13 -11
- data/lib/engine.rb +6 -7
- data/lib/infopark_component_cache.rb +1 -2
- data/lib/infopark_component_cache/abstract_cache_storage.rb +4 -3
- data/lib/infopark_component_cache/cache_storage.rb +1 -0
- data/lib/infopark_component_cache/component.rb +8 -6
- data/lib/infopark_component_cache/component_cache.rb +31 -30
- data/lib/infopark_component_cache/consistency_guard.rb +1 -1
- data/lib/infopark_component_cache/delayed_guard.rb +7 -7
- data/lib/infopark_component_cache/guards/cms_state_guard.rb +6 -5
- data/lib/infopark_component_cache/guards/last_changed.rb +5 -2
- data/lib/infopark_component_cache/guards/obj_count.rb +1 -1
- data/lib/infopark_component_cache/guards/valid_from.rb +7 -10
- data/lib/infopark_component_cache/guards/valid_until.rb +7 -9
- data/lib/infopark_component_cache/key_generator.rb +3 -3
- data/lib/infopark_component_cache/version.rb +1 -1
- data/lib/infopark_component_cache/volatile_cache.rb +1 -1
- data/lib/infopark_component_cache/volatile_cache_storage.rb +1 -0
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/config/application.rb +1 -2
- data/spec/dummy/config/boot.rb +5 -5
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/db/schema.rb +1 -2
- data/spec/lib/infopark_component_cache/component_cache_spec.rb +118 -0
- data/spec/lib/{delayed_guard_spec.rb → infopark_component_cache/delayed_guard_spec.rb} +3 -3
- data/spec/lib/{guards → infopark_component_cache/guards}/always_consistent_spec.rb +7 -6
- data/spec/lib/{guards → infopark_component_cache/guards}/last_changed_spec.rb +20 -12
- data/spec/lib/{guards → infopark_component_cache/guards}/never_consistent_spec.rb +7 -6
- data/spec/lib/{guards → infopark_component_cache/guards}/obj_count_spec.rb +20 -12
- data/spec/lib/{guards → infopark_component_cache/guards}/valid_from_spec.rb +20 -12
- data/spec/lib/{guards → infopark_component_cache/guards}/valid_until_spec.rb +23 -14
- data/spec/spec_helper.rb +8 -8
- data/spec/support/cache_switching_macros.rb +4 -4
- metadata +71 -23
- data/spec/lib/compontent_cache_spec.rb +0 -116
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe InfoparkComponentCache::Guards::ValidUntil do
|
4
|
+
subject(:guard) { described_class.new(cache_component_stub) }
|
5
|
+
|
4
6
|
let(:cache_component_stub) do
|
5
7
|
double.tap do |cache_component_stub|
|
6
8
|
cache_component_stub.stub(:cache_key) do |input|
|
@@ -9,7 +11,7 @@ describe InfoparkComponentCache::Guards::ValidUntil do
|
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
|
-
let(:minimum_valid_until) { 10.minutes.since
|
14
|
+
let(:minimum_valid_until) { 10.minutes.since }
|
13
15
|
|
14
16
|
let(:obj_stub) do
|
15
17
|
double.tap do |obj_stub|
|
@@ -23,8 +25,6 @@ describe InfoparkComponentCache::Guards::ValidUntil do
|
|
23
25
|
|
24
26
|
before { InfoparkComponentCache::CmsStateGuard.obj_root_class = obj_stub }
|
25
27
|
|
26
|
-
subject { described_class.new(cache_component_stub) }
|
27
|
-
|
28
28
|
context "with cache disabled" do
|
29
29
|
disable_cache
|
30
30
|
|
@@ -33,7 +33,8 @@ describe InfoparkComponentCache::Guards::ValidUntil do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
context "with a call to guard!" do
|
36
|
-
before {
|
36
|
+
before { guard.guard! }
|
37
|
+
|
37
38
|
it { is_expected.not_to be_consistent }
|
38
39
|
end
|
39
40
|
end
|
@@ -47,26 +48,34 @@ describe InfoparkComponentCache::Guards::ValidUntil do
|
|
47
48
|
end
|
48
49
|
|
49
50
|
context "with a call to guard!" do
|
50
|
-
before {
|
51
|
+
before { guard.guard! }
|
52
|
+
|
51
53
|
it { is_expected.to be_consistent }
|
52
54
|
end
|
53
55
|
|
54
|
-
context "after minimum valid until changes to a present date" do
|
55
|
-
before
|
56
|
-
|
56
|
+
context "when after minimum valid until changes to a present date" do
|
57
|
+
before do
|
58
|
+
guard.guard!
|
59
|
+
obj_stub.stub(:minimum).and_return(Time.now.to_iso)
|
60
|
+
end
|
61
|
+
|
57
62
|
it { is_expected.not_to be_consistent }
|
58
63
|
end
|
59
64
|
|
60
|
-
context "after minimum valid until changes to a past date" do
|
61
|
-
before
|
62
|
-
|
65
|
+
context "when after minimum valid until changes to a past date" do
|
66
|
+
before do
|
67
|
+
guard.guard!
|
68
|
+
obj_stub.stub(:minimum).and_return(1.month.ago.to_iso)
|
69
|
+
end
|
70
|
+
|
63
71
|
it { is_expected.not_to be_consistent }
|
64
72
|
end
|
65
73
|
|
66
|
-
context "nil valid until" do
|
74
|
+
context "when nil valid until" do
|
67
75
|
let(:minimum_valid_until) { nil }
|
68
76
|
|
69
|
-
before {
|
77
|
+
before { guard.guard! }
|
78
|
+
|
70
79
|
it { is_expected.to be_consistent }
|
71
80
|
end
|
72
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
ENV[
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
2
|
# Load dummy app
|
3
|
-
require File.expand_path("
|
3
|
+
require File.expand_path("dummy/config/environment.rb", __dir__)
|
4
4
|
# Load rspec components
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "rspec/rails"
|
6
|
+
require "byebug"
|
7
7
|
# Nice backtraces
|
8
8
|
Rails.backtrace_cleaner.remove_silencers!
|
9
9
|
# Load support files
|
10
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
11
11
|
|
12
12
|
# configure rspec
|
13
13
|
RSpec.configure do |config|
|
@@ -17,12 +17,12 @@ RSpec.configure do |config|
|
|
17
17
|
config.order = "random"
|
18
18
|
config.extend CacheSwitchingMacros
|
19
19
|
config.expect_with :rspec do |c|
|
20
|
-
c.syntax =
|
20
|
+
c.syntax = %i(should expect)
|
21
21
|
end
|
22
22
|
config.mock_with :rspec do |c|
|
23
|
-
c.syntax =
|
23
|
+
c.syntax = %i(should expect)
|
24
24
|
end
|
25
|
-
config.before
|
25
|
+
config.before do
|
26
26
|
Rails.cache.clear
|
27
27
|
end
|
28
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module CacheSwitchingMacros
|
2
|
-
def enable_cache(trigger
|
2
|
+
def enable_cache(trigger = :all)
|
3
3
|
before(trigger) do
|
4
4
|
@__perform_caching_before ||= []
|
5
5
|
@__perform_caching_before.push Rails.application.config.action_controller.perform_caching
|
@@ -7,13 +7,13 @@ module CacheSwitchingMacros
|
|
7
7
|
end
|
8
8
|
|
9
9
|
after(trigger) do
|
10
|
-
@__perform_caching_before ||=[]
|
10
|
+
@__perform_caching_before ||= []
|
11
11
|
previous_setting = @__perform_caching_before.pop || false
|
12
12
|
Rails.application.config.action_controller.perform_caching = previous_setting
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def disable_cache(trigger
|
16
|
+
def disable_cache(trigger = :all)
|
17
17
|
before(trigger) do
|
18
18
|
@__perform_caching_before ||= []
|
19
19
|
@__perform_caching_before.push Rails.application.config.action_controller.perform_caching
|
@@ -21,7 +21,7 @@ module CacheSwitchingMacros
|
|
21
21
|
end
|
22
22
|
|
23
23
|
after(trigger) do
|
24
|
-
@__perform_caching_before ||=[]
|
24
|
+
@__perform_caching_before ||= []
|
25
25
|
previous_setting = @__perform_caching_before.pop || false
|
26
26
|
Rails.application.config.action_controller.perform_caching = previous_setting
|
27
27
|
end
|
metadata
CHANGED
@@ -1,37 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infopark_component_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomasz Przedmojski, sveninfo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: infopark_fiona_connector
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 7.0.1.5.2.3.rc5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 7.0.1.5.2.3.rc5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
|
-
type: :
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
@@ -53,7 +67,21 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.5'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.87.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.87.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
87
|
- - ">="
|
@@ -67,7 +95,7 @@ dependencies:
|
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
98
|
+
name: rubocop-rspec
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - ">="
|
@@ -80,6 +108,20 @@ dependencies:
|
|
80
108
|
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.3.6
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.3.6
|
83
125
|
description: Easy and intelligent fragment caching for RailsConnector projects
|
84
126
|
email:
|
85
127
|
- tomasz.przedmojski@infopark.de
|
@@ -89,8 +131,14 @@ extra_rdoc_files: []
|
|
89
131
|
files:
|
90
132
|
- ".gitignore"
|
91
133
|
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- ".rubocop_todo.yml"
|
92
136
|
- ".ruby-version"
|
137
|
+
- ".travis.yml"
|
93
138
|
- Gemfile
|
139
|
+
- Gemfile.lock
|
140
|
+
- Gemfile.rails51
|
141
|
+
- Gemfile.rails51.lock
|
94
142
|
- LICENSE.txt
|
95
143
|
- README.md
|
96
144
|
- Rakefile
|
@@ -137,14 +185,14 @@ files:
|
|
137
185
|
- spec/dummy/db/development.sqlite3
|
138
186
|
- spec/dummy/db/schema.rb
|
139
187
|
- spec/dummy/log/.gitkeep
|
140
|
-
- spec/lib/
|
141
|
-
- spec/lib/delayed_guard_spec.rb
|
142
|
-
- spec/lib/guards/always_consistent_spec.rb
|
143
|
-
- spec/lib/guards/last_changed_spec.rb
|
144
|
-
- spec/lib/guards/never_consistent_spec.rb
|
145
|
-
- spec/lib/guards/obj_count_spec.rb
|
146
|
-
- spec/lib/guards/valid_from_spec.rb
|
147
|
-
- spec/lib/guards/valid_until_spec.rb
|
188
|
+
- spec/lib/infopark_component_cache/component_cache_spec.rb
|
189
|
+
- spec/lib/infopark_component_cache/delayed_guard_spec.rb
|
190
|
+
- spec/lib/infopark_component_cache/guards/always_consistent_spec.rb
|
191
|
+
- spec/lib/infopark_component_cache/guards/last_changed_spec.rb
|
192
|
+
- spec/lib/infopark_component_cache/guards/never_consistent_spec.rb
|
193
|
+
- spec/lib/infopark_component_cache/guards/obj_count_spec.rb
|
194
|
+
- spec/lib/infopark_component_cache/guards/valid_from_spec.rb
|
195
|
+
- spec/lib/infopark_component_cache/guards/valid_until_spec.rb
|
148
196
|
- spec/spec_helper.rb
|
149
197
|
- spec/support/cache_switching_macros.rb
|
150
198
|
homepage: ''
|
@@ -189,13 +237,13 @@ test_files:
|
|
189
237
|
- spec/dummy/db/development.sqlite3
|
190
238
|
- spec/dummy/db/schema.rb
|
191
239
|
- spec/dummy/log/.gitkeep
|
192
|
-
- spec/lib/
|
193
|
-
- spec/lib/delayed_guard_spec.rb
|
194
|
-
- spec/lib/guards/always_consistent_spec.rb
|
195
|
-
- spec/lib/guards/last_changed_spec.rb
|
196
|
-
- spec/lib/guards/never_consistent_spec.rb
|
197
|
-
- spec/lib/guards/obj_count_spec.rb
|
198
|
-
- spec/lib/guards/valid_from_spec.rb
|
199
|
-
- spec/lib/guards/valid_until_spec.rb
|
240
|
+
- spec/lib/infopark_component_cache/component_cache_spec.rb
|
241
|
+
- spec/lib/infopark_component_cache/delayed_guard_spec.rb
|
242
|
+
- spec/lib/infopark_component_cache/guards/always_consistent_spec.rb
|
243
|
+
- spec/lib/infopark_component_cache/guards/last_changed_spec.rb
|
244
|
+
- spec/lib/infopark_component_cache/guards/never_consistent_spec.rb
|
245
|
+
- spec/lib/infopark_component_cache/guards/obj_count_spec.rb
|
246
|
+
- spec/lib/infopark_component_cache/guards/valid_from_spec.rb
|
247
|
+
- spec/lib/infopark_component_cache/guards/valid_until_spec.rb
|
200
248
|
- spec/spec_helper.rb
|
201
249
|
- spec/support/cache_switching_macros.rb
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe InfoparkComponentCache::ComponentCache do
|
4
|
-
let(:obj) { double(name: 'spec_obj', id: 2001) }
|
5
|
-
let(:name) { 'spec_cached_component' }
|
6
|
-
let(:params) { {some: 'additional', params: 'supplied'} }
|
7
|
-
let(:guard) { Class.new(Struct.new(:component)) }
|
8
|
-
|
9
|
-
subject { described_class.new(obj, name, params, [guard]) }
|
10
|
-
|
11
|
-
context 'with caching disabled' do
|
12
|
-
before { allow(Rails.application.config.action_controller).to receive(:perform_caching).and_return(false) }
|
13
|
-
|
14
|
-
describe '#fetch' do
|
15
|
-
let(:value) { 'very_hard_computation_required_for_this_string' }
|
16
|
-
let(:specific_guard) { subject.guards.first }
|
17
|
-
|
18
|
-
it 'returns the passed the block value' do
|
19
|
-
expect(subject.fetch { value }).to eq(value)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'never calls any methods on the guard' do
|
23
|
-
expect(specific_guard).not_to receive(:consistent?)
|
24
|
-
expect(specific_guard).not_to receive(:guard!)
|
25
|
-
|
26
|
-
subject.fetch { value }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'with caching enabled' do
|
32
|
-
before { allow(Rails.application.config.action_controller).to receive(:perform_caching).and_return(true) }
|
33
|
-
|
34
|
-
let(:guard) { Class.new(InfoparkComponentCache::ConsistencyGuard) {
|
35
|
-
def consistent?
|
36
|
-
cache.exist?(:guard_called)
|
37
|
-
end
|
38
|
-
|
39
|
-
def guard!
|
40
|
-
cache.write(:guard_called, 1)
|
41
|
-
end
|
42
|
-
} }
|
43
|
-
|
44
|
-
describe '#fetch' do
|
45
|
-
let(:value) { 'very_hard_computation_required_for_this_string' }
|
46
|
-
let(:specific_guard) { subject.guards.first }
|
47
|
-
let(:computer) { double }
|
48
|
-
|
49
|
-
it 'returns the passed the block value' do
|
50
|
-
expect(subject.fetch { value }).to eq(value)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'calls the required methods on the guard' do
|
54
|
-
expect(specific_guard).to receive(:consistent?).exactly(3).times
|
55
|
-
expect(specific_guard).to receive(:guard!).exactly(3).times
|
56
|
-
|
57
|
-
3.times { subject.fetch { value } }
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'only evalues the block once' do
|
61
|
-
expect(computer).to receive(:compute).and_return(value).once
|
62
|
-
|
63
|
-
3.times { expect(subject.fetch { computer.compute }).to eq(value) }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '#compontent' do
|
69
|
-
subject { described_class.new(obj, name, params).component }
|
70
|
-
|
71
|
-
it 'stores the passed obj' do
|
72
|
-
expect(subject.obj).to eq(obj)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'stores the passed name' do
|
76
|
-
expect(subject.name).to eq(name)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'stores the passed params' do
|
80
|
-
expect(subject.params).to eq(params)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe '#guards' do
|
85
|
-
let(:guard_class1) { Struct.new(:component) }
|
86
|
-
let(:guard_class2) { Struct.new(:compontent, :extra) }
|
87
|
-
let(:guard_params) { {guard: guard_class2, something: 'more'} }
|
88
|
-
|
89
|
-
subject { described_class.new(obj, name, params, [guard_class1, guard_params]).guards }
|
90
|
-
|
91
|
-
it 'contains an array of passed guards' do
|
92
|
-
expect(subject).to match_array([
|
93
|
-
an_instance_of(guard_class1),
|
94
|
-
an_instance_of(guard_class2)
|
95
|
-
])
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'preserves the extra params' do
|
99
|
-
expect(subject.last.extra).to eq(guard_params)
|
100
|
-
end
|
101
|
-
|
102
|
-
context 'with no guards specified in the constructors' do
|
103
|
-
subject { described_class.new(obj, name, params).guards }
|
104
|
-
|
105
|
-
it 'contains standard guards' do
|
106
|
-
expect(subject).to match_array([
|
107
|
-
an_instance_of(InfoparkComponentCache::Guards::ValuePresent),
|
108
|
-
an_instance_of(InfoparkComponentCache::Guards::LastChanged),
|
109
|
-
an_instance_of(InfoparkComponentCache::Guards::ObjCount),
|
110
|
-
an_instance_of(InfoparkComponentCache::Guards::ValidFrom),
|
111
|
-
an_instance_of(InfoparkComponentCache::Guards::ValidUntil)
|
112
|
-
])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|