cached_resource 7.1.0 → 7.2.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: '0895f45566dd7c4ee2f394be6dda1c7a86aed9ad4e7c6a470d9a59d584c529c1'
4
- data.tar.gz: 16106c7680c3cd6708b8171aa5db5f3993f3a77368685876e3e125b03e2d8e85
3
+ metadata.gz: d1c2150c2dc21cf091c9b26674b3e52a7bd43938318704f7c2f0739a0b9756aa
4
+ data.tar.gz: 2f7b9665c688f2a60b7def43cfafbe2701accded9fcf9aabc371fe91bf78362d
5
5
  SHA512:
6
- metadata.gz: 0dbb4bc9fc1019dbf38dce7553b1ad15a964ca3699a461d551b892a26608b53ab0dbe4d8dbcce3878977f4b00debd88affa6494ad52d4fb2fb739a3ca6d239c3
7
- data.tar.gz: 689a7edad73b7de5cff68c17d34135422d7166b1ae2745ae3be398cc77399e1ccd2d09a8423a3c7fda00f647216834e4b93c0a82287c39dd5ea5177d3fc7072f
6
+ metadata.gz: c0c94c6b77f623a49a3259a69a4bb1b1d2d7fc219d590b740d5a86c71f3cfbf7eb783a2e8a2c06631c926bd2679b220341d8fbf03b77a3651d5219a70bb8d779
7
+ data.tar.gz: 207c37429a14511fb788d21bc69e86b01f8f59a303b20aebafb2f07e54aba48546c03a5ac7fa4b99da0bd9b7cd53d385ddb73306c643d9044d113ea638949e61
@@ -40,7 +40,7 @@ module CachedResource
40
40
  # Re/send the request to fetch the resource
41
41
  def find_via_reload(key, *arguments)
42
42
  object = find_without_cache(*arguments)
43
- return object unless cached_resource.enabled
43
+ return object unless should_cache?(object)
44
44
 
45
45
  cache_collection_synchronize(object, *arguments) if cached_resource.collection_synchronize
46
46
  return object if !cached_resource.cache_collections && is_any_collection?(*arguments)
@@ -79,6 +79,12 @@ module CachedResource
79
79
  end
80
80
  end
81
81
 
82
+ # Avoid cache nil or [] objects
83
+ def should_cache?(object)
84
+ return false unless cached_resource.enabled
85
+ object.respond_to?(:empty?) ? !object.empty? : !!object
86
+ end
87
+
82
88
  # Determine if the given arguments represent
83
89
  # the entire collection of objects.
84
90
  def is_collection?(*arguments)
@@ -1,3 +1,3 @@
1
1
  module CachedResource
2
- VERSION = "7.1.0"
2
+ VERSION = "7.2.0"
3
3
  end
@@ -33,6 +33,7 @@ describe CachedResource do
33
33
  @other_string_thing_json = @other_string_thing.to_json
34
34
  @date_thing_json = @date_thing.to_json
35
35
  @nil_thing = nil.to_json
36
+ @empty_array_thing = [].to_json
36
37
  @not_the_thing = {:not_the_thing => {:id => 1, :name => "Not"}}
37
38
  @not_the_thing_json = @not_the_thing.to_json
38
39
  end
@@ -59,6 +60,7 @@ describe CachedResource do
59
60
  mock.get "/things/1.json?foo=bar", {}, @thing_json
60
61
  mock.get "/things/fded.json", {}, @string_thing_json
61
62
  mock.get "/things.json?name=42", {}, @nil_thing, 404
63
+ mock.get "/things.json?name=43", {}, @empty_array_thing
62
64
  mock.get "/things/4.json", {}, @date_thing_json
63
65
  mock.get "/not_the_things/1.json", {}, @not_the_thing_json
64
66
  end
@@ -66,15 +68,19 @@ describe CachedResource do
66
68
 
67
69
  it "should cache a response" do
68
70
  result = Thing.find(1)
69
-
70
71
  read_from_cache("thing/1").should == result
71
72
  end
72
73
 
73
- it "should cache a nil response" do
74
- result = Thing.find(:all, :params => { :name => '42' })
74
+ it "shouldn't cache nil response" do
75
+ Thing.find(:all, :params => { :name => '42' })
75
76
  read_from_cache("thing/all/name/42").should == nil
76
77
  end
77
78
 
79
+ it "shouldn't cache [] response" do
80
+ Thing.find(:all, :params => { :name => '43' })
81
+ read_from_cache("thing/all/name/43").should == nil
82
+ end
83
+
78
84
  it "should cache a response for a string primary key" do
79
85
  result = Thing.find("fded")
80
86
  read_from_cache("thing/fded").should == result
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: 7.1.0
4
+ version: 7.2.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: 2024-01-18 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource