cached_resource 5.1.1 → 5.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2b25cc83718d786c0441bc7cb082944ac7aa4fe3d379792cacb96e87df668eb
4
- data.tar.gz: 8fa4f263faee071d9e7361f27b8927113bb36e76b1e5e765e993935cadad8c22
3
+ metadata.gz: 9fc8b21898febeea0df40b81f91f17d8ac7243024b600f9e6b9263da77157572
4
+ data.tar.gz: 3cec5573bcb480d2fee60403aec06aef1c6dc588ad4feeafd4cd16d60bbe6f79
5
5
  SHA512:
6
- metadata.gz: 0523763d1f6d1dd9eb1d68ddb2a196e8f737d5660c91bcb244374804b0ddc31f50037ebb19c0dc1a25b891586cf3b5025df60b16a11c209e03f0510147e78514
7
- data.tar.gz: 8ae89f1cd8fcf8dccedc053c7acc15b76ea84853240b0998ee31b5a17f837d001696866262182787d315d4f432f67d87b1ef4d9ef918b530b4e884f4e2f88363
6
+ metadata.gz: 5f2c6fc515e5365230aaa49a12200e8e57e41f4468812cf96847b16e827e0aedd6354428d282591c85ce18ff104038b7d561d7080bb6bb973f7161da871ecf41
7
+ data.tar.gz: 9fb5a752cd1084d88707478fb62957a3ee78bd8cc561d809e502e908c8dbcf3d627d0d20fb02c45ad9c1d7b52fa3756b8d5677535def16a96e5d07b0fb889205
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # CachedResource [![Build Status](https://secure.travis-ci.org/mhgbrown/cached_resource.png)](http://travis-ci.org/mhgbrown/cached_resource)
1
+ # CachedResource [![Build Status](https://travis-ci.org/mhgbrown/cached_resource.svg?branch=master)](http://travis-ci.org/mhgbrown/cached_resource)
2
2
  CachedResource is a Ruby gem whose goal is to increase the performance of interacting with web services via ActiveResource by caching responses based on request parameters. It can help reduce the lag created by making repeated requests across a network.
3
3
 
4
4
  ## Installation
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cached_resource (5.1.0)
4
+ cached_resource (5.1.1)
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.0)
4
+ cached_resource (5.1.1)
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.0)
4
+ cached_resource (5.1.1)
5
5
  activeresource (>= 4.0)
6
6
  activesupport (>= 4.0)
7
7
  nilio (>= 1.0)
@@ -85,13 +85,19 @@ module CachedResource
85
85
  # Read a entry from the cache for the given key.
86
86
  def cache_read(key)
87
87
  object = cached_resource.cache.read(key).try do |json_cache|
88
- cache = json_to_object(JSON.parse(json_cache, :symbolize_names => true))
89
- if cache.is_a? Enumerable
90
- restored = cache.map { |record| full_dup(record) }
91
- next restored unless respond_to?(:collection_parser)
92
- collection_parser.new(restored)
93
- else
94
- full_dup(cache)
88
+
89
+ # In older version JSON can't deserialize 'null' to nil
90
+ json = json_cache == 'null' ? nil : JSON.parse(json_cache, :symbolize_names => true)
91
+
92
+ unless json.nil?
93
+ cache = json_to_object(json)
94
+ if cache.is_a? Enumerable
95
+ restored = cache.map { |record| full_dup(record) }
96
+ next restored unless respond_to?(:collection_parser)
97
+ collection_parser.new(restored)
98
+ else
99
+ full_dup(cache)
100
+ end
95
101
  end
96
102
  end
97
103
  object && cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} READ #{key}")
@@ -137,6 +143,8 @@ module CachedResource
137
143
  def object_to_json(object)
138
144
  if object.is_a? Enumerable
139
145
  object.map { |o| { :object => o, :persistence => o.persisted? } }.to_json
146
+ elsif object.nil?
147
+ nil.to_json
140
148
  else
141
149
  { :object => object, :persistence => object.persisted? }.to_json
142
150
  end
@@ -1,3 +1,3 @@
1
1
  module CachedResource
2
- VERSION = "5.1.1"
2
+ VERSION = "5.1.2"
3
3
  end
@@ -23,6 +23,7 @@ describe CachedResource do
23
23
  @other_thing_json = @other_thing.to_json
24
24
  @string_thing_json = @string_thing.to_json
25
25
  @other_string_thing_json = @other_string_thing.to_json
26
+ @nil_thing = nil.to_json
26
27
  end
27
28
 
28
29
  after(:each) do
@@ -42,6 +43,7 @@ describe CachedResource do
42
43
  mock.get "/things/1.json", {}, @thing_json
43
44
  mock.get "/things/1.json?foo=bar", {}, @thing_json
44
45
  mock.get "/things/fded.json", {}, @string_thing_json
46
+ mock.get "/things.json?name=42", {}, @nil_thing, 404
45
47
  end
46
48
  end
47
49
 
@@ -51,6 +53,11 @@ describe CachedResource do
51
53
  read_from_cache("thing/1").should == result
52
54
  end
53
55
 
56
+ it "should cache a nil response" do
57
+ result = Thing.find(:all, :params => { :name => '42' })
58
+ read_from_cache("thing/all/name/42").should == nil
59
+ end
60
+
54
61
  it "should cache a response for a string primary key" do
55
62
  result = Thing.find("fded")
56
63
  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: 5.1.1
4
+ version: 5.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morgan Brown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-12 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource