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 +4 -4
- data/README.md +1 -1
- data/gemfiles/4.2.gemfile.lock +1 -1
- data/gemfiles/5.0.gemfile.lock +1 -1
- data/gemfiles/5.1.gemfile.lock +1 -1
- data/lib/cached_resource/caching.rb +15 -7
- data/lib/cached_resource/version.rb +1 -1
- data/spec/cached_resource/caching_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fc8b21898febeea0df40b81f91f17d8ac7243024b600f9e6b9263da77157572
|
4
|
+
data.tar.gz: 3cec5573bcb480d2fee60403aec06aef1c6dc588ad4feeafd4cd16d60bbe6f79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f2c6fc515e5365230aaa49a12200e8e57e41f4468812cf96847b16e827e0aedd6354428d282591c85ce18ff104038b7d561d7080bb6bb973f7161da871ecf41
|
7
|
+
data.tar.gz: 9fb5a752cd1084d88707478fb62957a3ee78bd8cc561d809e502e908c8dbcf3d627d0d20fb02c45ad9c1d7b52fa3756b8d5677535def16a96e5d07b0fb889205
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# CachedResource [![Build Status](https://
|
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
|
data/gemfiles/4.2.gemfile.lock
CHANGED
data/gemfiles/5.0.gemfile.lock
CHANGED
data/gemfiles/5.1.gemfile.lock
CHANGED
@@ -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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
@@ -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.
|
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:
|
11
|
+
date: 2019-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|