cached_resource 5.2.0 → 5.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29a5076e42c43b34a6d5b430c8dc16ce062dd3f7f1ac4f63f992efef03b3ccf9
4
- data.tar.gz: ff819f199885c83cb65a6e21d1a319c5bb6b747dd467870c913043765fbfa111
3
+ metadata.gz: 7102fd60421cc8ddea333b62047f5bf15dcc07e1ac38444084f8815d728ad386
4
+ data.tar.gz: 51e3b4a15b4094cdcfeda312a10b44aaff7f1da7143020c5100cd55b7f8dd22e
5
5
  SHA512:
6
- metadata.gz: ea526acccd50610cf5c39248c9c0180c7a6ca1ca42cb6975df9b6f97b668febda6fc17684e9a9a7ca4b371798019d7d5e818e7a34e428702aeb5f475859ddbae
7
- data.tar.gz: cc087aa9dcc0ad28b8779cf4412fd999b84019b7398d610e2e9e271b14d550bb9baa9dd039a0fa10da6bd15c83f76cba843769723e7bd0ca13a8d3f2f24c0e5e
6
+ metadata.gz: 789e3ab01ffa4dd155a7587cab2d6f92455c0e9a8e2d8ce429b562c626be43eaadbfda3a44d13e09cb998c5e51805042eb7cd7463adc6b7f1e8cc25e2e77628e
7
+ data.tar.gz: 636d931d7de4ab7068d3f68704c4832f6216be8b0d7d50cc28797fb55389e8d2b0199b78685b57d5c48f8d596c6bf0e96a58f24d75a2a9b89467688de90140b3
data/README.md CHANGED
@@ -53,6 +53,7 @@ CachedResource accepts the following options:
53
53
  * `:collection_arguments` The arguments that identify the principal collection request. Default: `[:all]`
54
54
  * `:logger` The logger to which CachedResource messages should be written. Default: The `Rails.logger` if available, or an `ActiveSupport::Logger`
55
55
  * `:cache` The cache store that CacheResource should use. Default: The `Rails.cache` if available, or an `ActiveSupport::Cache::MemoryStore`
56
+ * `:cache_collections` Set to false to always remake a request for collections. Default: `true`
56
57
 
57
58
  You can set them like this:
58
59
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cached_resource (5.1.3)
4
+ cached_resource (5.3.0)
5
5
  activeresource (>= 4.0)
6
6
  activesupport (>= 4.0)
7
7
  nilio (>= 1.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cached_resource (5.1.3)
4
+ cached_resource (5.3.0)
5
5
  activeresource (>= 4.0)
6
6
  activesupport (>= 4.0)
7
7
  nilio (>= 1.0)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cached_resource (5.1.3)
4
+ cached_resource (5.3.0)
5
5
  activeresource (>= 4.0)
6
6
  activesupport (>= 4.0)
7
7
  nilio (>= 1.0)
@@ -17,6 +17,7 @@ module CachedResource
17
17
  def find_with_cache(*arguments)
18
18
  arguments << {} unless arguments.last.is_a?(Hash)
19
19
  should_reload = arguments.last.delete(:reload) || !cached_resource.enabled
20
+ should_reload = true if !cached_resource.cache_collections && is_any_collection?(*arguments)
20
21
  arguments.pop if arguments.last.empty?
21
22
  key = cache_key(arguments)
22
23
 
@@ -41,6 +42,7 @@ module CachedResource
41
42
  def find_via_reload(key, *arguments)
42
43
  object = find_without_cache(*arguments)
43
44
  cache_collection_synchronize(object, *arguments) if cached_resource.collection_synchronize
45
+ return object if !cached_resource.cache_collections && is_any_collection?(*arguments)
44
46
  cache_write(key, object)
45
47
  cache_read(key)
46
48
  end
@@ -82,6 +84,12 @@ module CachedResource
82
84
  arguments == cached_resource.collection_arguments
83
85
  end
84
86
 
87
+ # Determine if the given arguments represent
88
+ # any collection of objects
89
+ def is_any_collection?(*arguments)
90
+ cached_resource.collection_arguments.all?{ |arg| arguments.include?(arg) } || arguments.include?(:all)
91
+ end
92
+
85
93
  # Read a entry from the cache for the given key.
86
94
  def cache_read(key)
87
95
  object = cached_resource.cache.read(key).try do |json_cache|
@@ -22,7 +22,8 @@ module CachedResource
22
22
  # :collection_synchronize, default: false,
23
23
  # :collection_arguments, default: [:all]
24
24
  # :cache, default: Rails.cache or ActiveSupport::Cache::MemoryStore.new,
25
- # :logger, default: Rails.logger or ActiveSupport::Logger.new(NilIO.new)
25
+ # :logger, default: Rails.logger or ActiveSupport::Logger.new(NilIO.new),
26
+ # :cache_collections, default: true
26
27
  def initialize(options={})
27
28
  super({
28
29
  :enabled => true,
@@ -33,7 +34,8 @@ module CachedResource
33
34
  :collection_synchronize => false,
34
35
  :collection_arguments => [:all],
35
36
  :cache => defined?(Rails.cache) && Rails.cache || CACHE,
36
- :logger => defined?(Rails.logger) && Rails.logger || LOGGER
37
+ :logger => defined?(Rails.logger) && Rails.logger || LOGGER,
38
+ :cache_collections => true
37
39
  }.merge(options))
38
40
  end
39
41
 
@@ -1,3 +1,3 @@
1
1
  module CachedResource
2
- VERSION = "5.2.0"
2
+ VERSION = "5.3.0"
3
3
  end
@@ -565,4 +565,37 @@ describe CachedResource do
565
565
  new_result.name.should_not == old_result.name
566
566
  end
567
567
  end
568
+
569
+ describe "when cache_collections is disabled" do
570
+ before(:each) do
571
+ Thing.cached_resource.cache.clear
572
+ Thing.cached_resource.cache_collections = false
573
+
574
+ ActiveResource::HttpMock.reset!
575
+ ActiveResource::HttpMock.respond_to do |mock|
576
+ mock.get "/things.json", {}, [@thing[:thing],@string_thing[:thing]].to_json(:root => :thing)
577
+ mock.get "/things/1.json", {}, @thing_json
578
+ mock.get "/things/fded.json", {}, @string_thing_json
579
+ end
580
+ end
581
+
582
+ it "should cache a response" do
583
+ result = Thing.find(1)
584
+ read_from_cache("thing/1").should == result
585
+ end
586
+
587
+ it "should not remake a single request" do
588
+ result = Thing.find(1)
589
+ ActiveResource::HttpMock.requests.length.should == 1
590
+ result = Thing.find(1)
591
+ ActiveResource::HttpMock.requests.length.should == 1
592
+ end
593
+
594
+ it "should always remake the request for collections" do
595
+ Thing.all
596
+ ActiveResource::HttpMock.requests.length.should == 1
597
+ Thing.all
598
+ ActiveResource::HttpMock.requests.length.should == 2
599
+ end
600
+ end
568
601
  end
@@ -22,6 +22,10 @@ describe "CachedResource::Configuration" do
22
22
  configuration.collection_arguments.should == [:all]
23
23
  end
24
24
 
25
+ it "should cache collections" do
26
+ configuration.cache_collections == true
27
+ end
28
+
25
29
  describe "outside a Rails environment" do
26
30
  it "should be logging to a buffered logger attached to a NilIO" do
27
31
  configuration.logger.class.should == default_logger
@@ -72,7 +76,8 @@ describe "CachedResource::Configuration" do
72
76
  :enabled => false,
73
77
  :collection_synchronize => true,
74
78
  :collection_arguments => [:every],
75
- :custom => "irrelevant"
79
+ :custom => "irrelevant",
80
+ :cache_collections => true
76
81
  end
77
82
  end
78
83
 
@@ -90,6 +95,7 @@ describe "CachedResource::Configuration" do
90
95
  cr.collection_synchronize.should == true
91
96
  cr.collection_arguments.should == [:every]
92
97
  cr.custom.should == "irrelevant"
98
+ cr.cache_collections.should == true
93
99
  end
94
100
  end
95
101
 
@@ -130,7 +136,8 @@ describe "CachedResource::Configuration" do
130
136
  :enabled => false,
131
137
  :collection_synchronize => true,
132
138
  :collection_arguments => [:every],
133
- :custom => "irrelevant"
139
+ :custom => "irrelevant",
140
+ :cache_collections => true
134
141
  end
135
142
 
136
143
  class Foo < Bar
@@ -158,7 +165,8 @@ describe "CachedResource::Configuration" do
158
165
  :enabled => false,
159
166
  :collection_synchronize => true,
160
167
  :collection_arguments => [:every],
161
- :custom => "irrelevant"
168
+ :custom => "irrelevant",
169
+ :cache_collections => true
162
170
  end
163
171
 
164
172
  class Foo < Bar
@@ -186,6 +194,7 @@ describe "CachedResource::Configuration" do
186
194
  cr.custom.should == nil
187
195
  cr.ttl_randomization.should == false
188
196
  cr.ttl_randomization_scale.should == (1..2)
197
+ cr.cache_collections.should == true
189
198
  expect(cr.race_condition_ttl).to eq(86400)
190
199
  end
191
200
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cached_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morgan Brown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-04 00:00:00.000000000 Z
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -143,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.0.8
146
+ rubygems_version: 3.0.9
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Caching for ActiveResource