cached_resource 4.0.0 → 4.1.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 +4 -4
- data/README.md +10 -0
- data/cached_resource.gemspec +2 -2
- data/lib/cached_resource/caching.rb +3 -1
- data/lib/cached_resource/version.rb +1 -1
- data/spec/cached_resource/caching_spec.rb +27 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e681f36b01cd42d9dc1f81d123715a52761239b8
|
4
|
+
data.tar.gz: c0993c173aa2455c4ba9235491fcafc7b06302d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89d643a0e8a62872af14be969dd433be66e911e067ae6427e0ed95d2b493c4b97ea04355a78d0707a80f8ec03feadbb9da28c79b7fd5ecf7eca1168c43c2b8b
|
7
|
+
data.tar.gz: 67cbb77acac9166d0a83273de0ced52360c96deb0a5e67c5cac52a8925614dcc33a1a09703852efb729f47345b628d27a0cb49881926e8ba726661aeb91f2ada
|
data/README.md
CHANGED
@@ -16,6 +16,7 @@ CachedResource is designed to be framework agnostic, but will hook into Rails fo
|
|
16
16
|
|
17
17
|
* 3.2.x
|
18
18
|
* 4.0.0
|
19
|
+
* 4.1.x
|
19
20
|
|
20
21
|
## Configuration
|
21
22
|
**Set up CachedResource across all ActiveResources:**
|
@@ -104,6 +105,15 @@ If you need to clear the entire cache just do the following:
|
|
104
105
|
|
105
106
|
MyActiveResource.clear_cache
|
106
107
|
|
108
|
+
---
|
109
|
+
Sometimes you might have a case the resource pathing is non-unique per call. This can create a situation where your caching the same result for multiple calls:
|
110
|
+
|
111
|
+
MyActiveResource.find(:one, from: "/admin/shop.json")
|
112
|
+
|
113
|
+
Since resources are cached with an argument based key, you may pass in extra data to be appended to the cache key:
|
114
|
+
|
115
|
+
MyActiveResource.find(:one, from: "/admin/shop.json", uid: "unique value")
|
116
|
+
|
107
117
|
## Testing
|
108
118
|
rake
|
109
119
|
|
data/cached_resource.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "cached_resource/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "cached_resource"
|
7
7
|
s.version = CachedResource::VERSION
|
8
|
-
s.authors = "
|
9
|
-
s.email = "
|
8
|
+
s.authors = "Morgan Brown"
|
9
|
+
s.email = "brown.mhg@gmail.com"
|
10
10
|
s.homepage = "http://github.com/Ahsizara/cached_resource"
|
11
11
|
s.summary = %q{Caching for ActiveResource}
|
12
12
|
s.description = %q{Enables request-based caching for ActiveResource}
|
@@ -85,7 +85,9 @@ module CachedResource
|
|
85
85
|
def cache_read(key)
|
86
86
|
object = cached_resource.cache.read(key).try do |cache|
|
87
87
|
if cache.is_a? Enumerable
|
88
|
-
cache.map { |record| full_dup(record) }
|
88
|
+
restored = cache.map { |record| full_dup(record) }
|
89
|
+
next restored unless respond_to?(:collection_parser)
|
90
|
+
collection_parser.new(restored)
|
89
91
|
else
|
90
92
|
full_dup(cache)
|
91
93
|
end
|
@@ -153,6 +153,29 @@ describe CachedResource do
|
|
153
153
|
result1.should_not be_frozen
|
154
154
|
end
|
155
155
|
|
156
|
+
shared_examples "collection_return_type" do
|
157
|
+
if ActiveResource::VERSION::MAJOR >= 4
|
158
|
+
it "should return an ActiveResource::Collection" do
|
159
|
+
cached = Thing.cached_resource.cache.read("thing/all")
|
160
|
+
cached.should be_instance_of(ActiveResource::Collection)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should return an instance of the collection_parser" do
|
164
|
+
Thing.cached_resource.cache.clear
|
165
|
+
class CustomCollection < ActiveResource::Collection; end
|
166
|
+
Thing.collection_parser = CustomCollection
|
167
|
+
Thing.all
|
168
|
+
cached = Thing.cached_resource.cache.read("thing/all")
|
169
|
+
cached.should be_instance_of(CustomCollection)
|
170
|
+
end
|
171
|
+
else
|
172
|
+
it "should return an Array" do
|
173
|
+
cached = Thing.cached_resource.cache.read("thing/all")
|
174
|
+
cached.should be_instance_of(Array)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
156
179
|
shared_examples "collection_freezing" do
|
157
180
|
it "should not return a frozen collection on first request" do
|
158
181
|
Thing.cached_resource.cache.clear
|
@@ -221,6 +244,8 @@ describe CachedResource do
|
|
221
244
|
Thing.all
|
222
245
|
end
|
223
246
|
|
247
|
+
include_examples "collection_return_type"
|
248
|
+
|
224
249
|
include_examples "collection_freezing"
|
225
250
|
|
226
251
|
it "should write cache entries for its members" do
|
@@ -358,6 +383,8 @@ describe CachedResource do
|
|
358
383
|
Thing.all
|
359
384
|
end
|
360
385
|
|
386
|
+
include_examples "collection_return_type"
|
387
|
+
|
361
388
|
include_examples "collection_freezing"
|
362
389
|
|
363
390
|
it "should not write cache entries for its members" do
|
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: 4.
|
4
|
+
version: 4.1.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: 2014-
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Enables request-based caching for ActiveResource
|
84
|
-
email:
|
84
|
+
email: brown.mhg@gmail.com
|
85
85
|
executables: []
|
86
86
|
extensions: []
|
87
87
|
extra_rdoc_files: []
|