checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- data.tar.gz: 5a25521a92a1fb2800c9734c31f422b824fa1b40
4
- metadata.gz: 6451d12d14761ee761281ef929608e6c2c30f4b9
5
- SHA512:
6
- data.tar.gz: 63e554366a04e5b6e6a80042c17548a2845f5b9437e3dbed4dbb664cc1ca791c35677f08c778933dfd2f3661492b39ea0d4bd11db7a0bbd263cc04100519a253
7
- metadata.gz: 0a2b8a5cdb2b20fea4f93e1eb311145e1c81e9c705c5e1a42fb140cbce9c5a06efb765474d395f09462037c5ca23072f973e08b623b83767eb2cc3fc5b938b85
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9fc8b21898febeea0df40b81f91f17d8ac7243024b600f9e6b9263da77157572
4
+ data.tar.gz: 3cec5573bcb480d2fee60403aec06aef1c6dc588ad4feeafd4cd16d60bbe6f79
5
+ SHA512:
6
+ metadata.gz: 5f2c6fc515e5365230aaa49a12200e8e57e41f4468812cf96847b16e827e0aedd6354428d282591c85ce18ff104038b7d561d7080bb6bb973f7161da871ecf41
7
+ data.tar.gz: 9fb5a752cd1084d88707478fb62957a3ee78bd8cc561d809e502e908c8dbcf3d627d0d20fb02c45ad9c1d7b52fa3756b8d5677535def16a96e5d07b0fb889205
data/.travis.yml CHANGED
@@ -1,12 +1,13 @@
1
1
language: ruby
2
2
sudo: false
3
+ cache: bundler
4
+
3
5
rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
6
+ - 2.2.4
7
+ - 2.3.4
8
+ - 2.4.1
7
- - 2.2.3
8
9
9
10
gemfile:
10
- - gemfiles/Gemfile.rails-3.2.x
11
- - Gemfile
12
-
11
+ - gemfiles/4.2.gemfile
12
+ - gemfiles/5.0.gemfile
13
+ - gemfiles/5.1.gemfile
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "4.2" do
2
+ gem "rails", "~> 4.2.0"
3
+ end
4
+
5
+ appraise "5.0" do
6
+ gem "rails", "~> 5.0.0"
7
+ end
8
+
9
+ appraise "5.1" do
10
+ gem "rails", "~> 5.1.0"
11
+ end
data/{MIT-LICENSE → LICENSE} RENAMED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Andrew Chan
1
+ Copyright (c) 2018 Morgan Brown
2
2
3
3
Permission is hereby granted, free of charge, to any person obtaining
4
4
a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,35 +1,45 @@
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
5
- gem install cached_resource
5
+
6
+ ```ruby
7
+ gem install cached_resource
8
+ ```
6
9
7
10
## Compatibility
8
11
CachedResource supports the following Ruby versions:
9
12
10
- * 1.9.2, 1.9.3
11
- * 2.0.0, 2.1.0, 2.2.3
13
+ * 2.2.x
14
+ * 2.3.x
15
+ * 2.4.x
16
+
17
+ ...and likely other modern Ruby versions. If you require 1.8.7 support, please use version 2.3.4.
12
18
13
- If you require 1.8.7 support, please use version 2.3.4.
19
+ CachedResource is designed to be framework agnostic, but will hook into Rails for caching and logging if available. The latest CachedResource officially supports the following Rails versions:
14
20
15
- CachedResource is designed to be framework agnostic, but will hook into Rails for caching and logging if available. CachedResource officially supports the following Rails versions:
21
+ * 4.2.x
22
+ * 5.0.x
23
+ * 5.1.x
16
24
17
- * 3.2.x
25
+ For previously supported versions, use 4.2.0 or below.
18
- * 4.0.0
19
- * 4.1.x
20
26
21
27
## Configuration
22
28
**Set up CachedResource across all ActiveResources:**
23
29
24
- class ActiveResource::Base
25
- cached_resource
26
- end
30
+ ```ruby
31
+ class ActiveResource::Base
32
+ cached_resource
33
+ end
34
+ ```
27
35
28
36
Or set up CachedResource for a single class:
29
37
30
- class MyActiveResource < ActiveResource::Base
31
- cached_resource
32
- end
38
+ ```ruby
39
+ class MyActiveResource < ActiveResource::Base
40
+ cached_resource
41
+ end
42
+ ```
33
43
34
44
### Options
35
45
CachedResource accepts the following options:
@@ -41,96 +51,126 @@ CachedResource accepts the following options:
41
51
* `:ttl_randomization_scale` A Range from which a random value will be selected to scale the ttl. Default: `1..2`
42
52
* `:collection_synchronize` Use collections to generate cache entries for individuals. Update the existing cached principal collection when retrieving subsets of the principal collection or individuals. Default: `false`
43
53
* `:collection_arguments` The arguments that identify the principal collection request. Default: `[:all]`
44
- * `:logger` The logger to which CachedResource messages should be written. Default: The `Rails.logger` if available, or an `ActiveSupport::BufferedLogger`
54
+ * `:logger` The logger to which CachedResource messages should be written. Default: The `Rails.logger` if available, or an `ActiveSupport::Logger`
45
55
* `:cache` The cache store that CacheResource should use. Default: The `Rails.cache` if available, or an `ActiveSupport::Cache::MemoryStore`
46
56
47
57
You can set them like this:
48
58
49
- cached_resource :cache => MyCacheStore.new, :ttl => 60, :collection_synchronize => true, :logger => MyLogger.new
59
+ ```ruby
60
+ cached_resource :cache => MyCacheStore.new, :ttl => 60, :collection_synchronize => true, :logger => MyLogger.new
61
+ ```
50
62
51
63
You can also change them on the fly.
52
64
53
65
Turn CachedResource off. This will cause all responses to be retrieved normally (i.e. via the network). All responses will still be cached.
54
66
55
- MyActiveResource.cached_resource.off!
67
+ ```ruby
68
+ MyActiveResource.cached_resource.off!
69
+ ```
56
70
57
71
Turn CachedResource on.
58
-
59
- MyActiveResource.cached_resource.on!
72
+ ```ruby
73
+ MyActiveResource.cached_resource.on!
74
+ ```
60
75
61
76
Set the cache expiry time to 60 seconds.
62
77
63
- MyActiveResource.cached_resource.ttl = 60
78
+ ```ruby
79
+ MyActiveResource.cached_resource.ttl = 60
80
+ ```
64
81
65
82
Enable cache expiry time randomization, allowing it to fall randomly between 60 and 120 seconds.
66
83
67
- MyActiveResource.cached_resource.ttl_randomization = true
84
+ ```ruby
85
+ MyActiveResource.cached_resource.ttl_randomization = true
86
+ ```
68
87
69
88
Change the cache expiry time randomization scale so that the cache expiry time falls randomly between 30 and 180 seconds.
70
89
71
- MyActiveResource.cached_resource.ttl_randomization_scale = 0.5..3
72
-
90
+ ```ruby
91
+ MyActiveResource.cached_resource.ttl_randomization_scale = 0.5..3
92
+ ```
73
93
Enable collection synchronization. This will cause a call to `MyActiveResource.all` to also create cache entries for each of its members. So, for example, a later call to `MyActiveResource.find(1)` will be read from the cache instead of requested from the remote service.
74
94
75
- MyActiveResource.cached_resource.collection_synchronize = true
76
-
95
+ ```ruby
96
+ MyActiveResource.cached_resource.collection_synchronize = true
97
+ ```
77
98
Change the arguments that identify the principal collection request. If for some reason you are concerned with a collection that is retrieved at a "non-standard" URL, you may specify the Ruby arguments that produce that URL. When `collection_synchronize` is `true`, the collection returned from a request that matches these arguments will be cached and later updated when one of its members or a subset is retrieved.
78
99
79
- MyActiveResource.cached_resource.collection_arguments = [:all, :params => {:name => "Bob"}]
80
-
100
+ ```ruby
101
+ MyActiveResource.cached_resource.collection_arguments = [:all, :params => {:name => "Bob"}]
102
+ ```
81
103
Set a different logger.
82
104
83
- MyActiveResource.cached_resource.logger = MyLogger.new
84
-
105
+ ```ruby
106
+ MyActiveResource.cached_resource.logger = MyLogger.new
107
+ ```
85
108
Set a different cache store.
86
109
87
- MyActiveResource.cached_resource.cache = MyCacheStore.new
110
+ ```ruby
111
+ MyActiveResource.cached_resource.cache = MyCacheStore.new
112
+ ```
88
113
89
114
### Caveats
90
115
If you set up CachedResource across all ActiveResources or any subclass of ActiveResource that will be inherited by other classes and you want some of those others to have independent CachedResource configurations, then check out the example below:
91
116
92
- class ActiveResource::Base
93
- cached_resource
94
- end
95
-
96
- class MyActiveResource < ActiveResource::Base
97
- self.cached_resource = CachedResource::Configuration.new(:collection_synchronize => true)
98
- end
99
-
117
+ ```ruby
118
+ class ActiveResource::Base
119
+ cached_resource
120
+ end
121
+ ```
122
+
123
+ ```ruby
124
+ class MyActiveResource < ActiveResource::Base
125
+ self.cached_resource = CachedResource::Configuration.new(:collection_synchronize => true)
126
+ end
127
+ ```
100
128
## Usage
101
129
Sit back and relax! If you need to reload a particular request you can pass `:reload => true` into the options hash like this:
102
130
103
- MyActiveResource.find(:all, :reload => true)
104
-
131
+ ```ruby
132
+ MyActiveResource.find(:all, :reload => true)
133
+ ```
105
134
If you need to clear the entire cache just do the following:
106
135
107
- MyActiveResource.clear_cache
108
-
136
+ ```ruby
137
+ MyActiveResource.clear_cache
138
+ ```
109
139
---
110
140
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:
111
141
112
- MyActiveResource.find(:one, from: "/admin/shop.json")
142
+ ```ruby
143
+ MyActiveResource.find(:one, from: "/admin/shop.json")
144
+ ```
113
145
114
146
Since resources are cached with an argument based key, you may pass in extra data to be appended to the cache key:
115
-
116
- MyActiveResource.find(:one, from: "/admin/shop.json", uid: "unique value")
117
-
147
+
148
+ ```ruby
149
+ MyActiveResource.find(:one, from: "/admin/shop.json", uid: "unique value")
150
+ ```
118
151
## Testing
119
- rake
120
152
121
- ## Credit/Inspiration
122
- * quamen and [this gist](http://gist.github.com/947734)
123
- * latimes and [this plugin](http://github.com/latimes/cached_resource)
153
+ ```ruby
154
+ rake
155
+ ```
124
156
125
- ## Feedback/Problems
157
+ or to test all supported environments, make sure appraisal is setup
126
- Feedback is greatly appreciated! Check out this project's [issue tracker](https://github.com/Ahsizara/cached_resource/issues) if you've got anything to say.
127
158
128
- ## Future Considerations
129
- This may change at any time.
159
+ ```ruby
160
+ bundle exec appraisal install
161
+ ```
130
162
131
- * Callbacks on before and after reload
163
+ and then run
132
- * Consider checksums to improve the determination of freshness/changédness
133
164
165
+ ```ruby
166
+ bundle exec appraisal rake
167
+ ```
134
168
169
+ For more details, head over to the [appraisal](https://github.com/thoughtbot/appraisal) documentation.
135
170
171
+ ## Credit/Inspiration
172
+ * quamen and [this gist](http://gist.github.com/947734)
173
+ * latimes and [this plugin](http://github.com/latimes/cached_resource)
136
174
175
+ ## Feedback/Problems
176
+ Feedback is greatly appreciated! Check out this project's [issue tracker](https://github.com/Ahsizara/cached_resource/issues) if you've got anything to say.
data/cached_resource.gemspec CHANGED
@@ -7,19 +7,21 @@ Gem::Specification.new do |s|
7
7
s.version = CachedResource::VERSION
8
8
s.authors = "Morgan Brown"
9
9
s.email = "brown.mhg@gmail.com"
10
- s.homepage = "http://github.com/Ahsizara/cached_resource"
10
+ s.homepage = "https://github.com/mhgbrown/cached_resource"
11
11
s.summary = %q{Caching for ActiveResource}
12
12
s.description = %q{Enables request-based caching for ActiveResource}
13
+ s.licenses = ['MIT']
13
14
14
15
s.files = `git ls-files`.split("\n")
15
16
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
17
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
18
s.require_paths = ["lib"]
18
19
19
- s.add_dependency "rake"
20
- s.add_dependency "activeresource", ">= 3.2"
21
- s.add_dependency "activesupport", ">= 3.2"
20
+ s.add_runtime_dependency "activeresource", ">= 4.0"
21
+ s.add_runtime_dependency "activesupport", ">= 4.0"
22
+ s.add_runtime_dependency "nilio", ">= 1.0"
22
- s.add_dependency "nilio", ">= 1.0"
23
23
24
+ s.add_development_dependency "rake"
24
25
s.add_development_dependency "rspec"
26
+ s.add_development_dependency "appraisal"
25
27
end
data/gemfiles/4.2.gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+
7
+ gemspec path: "../"
data/gemfiles/4.2.gemfile.lock ADDED
@@ -0,0 +1,140 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ cached_resource (5.1.1)
5
+ activeresource (>= 4.0)
6
+ activesupport (>= 4.0)
7
+ nilio (>= 1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actionmailer (4.2.9)
13
+ actionpack (= 4.2.9)
14
+ actionview (= 4.2.9)
15
+ activejob (= 4.2.9)
16
+ mail (~> 2.5, >= 2.5.4)
17
+ rails-dom-testing (~> 1.0, >= 1.0.5)
18
+ actionpack (4.2.9)
19
+ actionview (= 4.2.9)
20
+ activesupport (= 4.2.9)
21
+ rack (~> 1.6)
22
+ rack-test (~> 0.6.2)
23
+ rails-dom-testing (~> 1.0, >= 1.0.5)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
+ actionview (4.2.9)
26
+ activesupport (= 4.2.9)
27
+ builder (~> 3.1)
28
+ erubis (~> 2.7.0)
29
+ rails-dom-testing (~> 1.0, >= 1.0.5)
30
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
31
+ activejob (4.2.9)
32
+ activesupport (= 4.2.9)
33
+ globalid (>= 0.3.0)
34
+ activemodel (4.2.9)
35
+ activesupport (= 4.2.9)
36
+ builder (~> 3.1)
37
+ activerecord (4.2.9)
38
+ activemodel (= 4.2.9)
39
+ activesupport (= 4.2.9)
40
+ arel (~> 6.0)
41
+ activeresource (4.1.0)
42
+ activemodel (~> 4.0)
43
+ activesupport (~> 4.0)
44
+ rails-observers (~> 0.1.2)
45
+ activesupport (4.2.9)
46
+ i18n (~> 0.7)
47
+ minitest (~> 5.1)
48
+ thread_safe (~> 0.3, >= 0.3.4)
49
+ tzinfo (~> 1.1)
50
+ appraisal (2.2.0)
51
+ bundler
52
+ rake
53
+ thor (>= 0.14.0)
54
+ arel (6.0.4)
55
+ builder (3.2.3)
56
+ concurrent-ruby (1.0.5)
57
+ diff-lcs (1.3)
58
+ erubis (2.7.0)
59
+ globalid (0.4.0)
60
+ activesupport (>= 4.2.0)
61
+ i18n (0.8.4)
62
+ loofah (2.0.3)
63
+ nokogiri (>= 1.5.9)
64
+ mail (2.6.6)
65
+ mime-types (>= 1.16, < 4)
66
+ mime-types (3.1)
67
+ mime-types-data (~> 3.2015)
68
+ mime-types-data (3.2016.0521)
69
+ mini_portile2 (2.2.0)
70
+ minitest (5.10.2)
71
+ nilio (1.0.0)
72
+ nokogiri (1.8.0)
73
+ mini_portile2 (~> 2.2.0)
74
+ rack (1.6.8)
75
+ rack-test (0.6.3)
76
+ rack (>= 1.0)
77
+ rails (4.2.9)
78
+ actionmailer (= 4.2.9)
79
+ actionpack (= 4.2.9)
80
+ actionview (= 4.2.9)
81
+ activejob (= 4.2.9)
82
+ activemodel (= 4.2.9)
83
+ activerecord (= 4.2.9)
84
+ activesupport (= 4.2.9)
85
+ bundler (>= 1.3.0, < 2.0)
86
+ railties (= 4.2.9)
87
+ sprockets-rails
88
+ rails-deprecated_sanitizer (1.0.3)
89
+ activesupport (>= 4.2.0.alpha)
90
+ rails-dom-testing (1.0.8)
91
+ activesupport (>= 4.2.0.beta, < 5.0)
92
+ nokogiri (~> 1.6)
93
+ rails-deprecated_sanitizer (>= 1.0.1)
94
+ rails-html-sanitizer (1.0.3)
95
+ loofah (~> 2.0)
96
+ rails-observers (0.1.4)
97
+ activemodel (>= 4.0)
98
+ railties (4.2.9)
99
+ actionpack (= 4.2.9)
100
+ activesupport (= 4.2.9)
101
+ rake (>= 0.8.7)
102
+ thor (>= 0.18.1, < 2.0)
103
+ rake (12.0.0)
104
+ rspec (3.6.0)
105
+ rspec-core (~> 3.6.0)
106
+ rspec-expectations (~> 3.6.0)
107
+ rspec-mocks (~> 3.6.0)
108
+ rspec-core (3.6.0)
109
+ rspec-support (~> 3.6.0)
110
+ rspec-expectations (3.6.0)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.6.0)
113
+ rspec-mocks (3.6.0)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.6.0)
116
+ rspec-support (3.6.0)
117
+ sprockets (3.7.1)
118
+ concurrent-ruby (~> 1.0)
119
+ rack (> 1, < 3)
120
+ sprockets-rails (3.2.0)
121
+ actionpack (>= 4.0)
122
+ activesupport (>= 4.0)
123
+ sprockets (>= 3.0.0)
124
+ thor (0.19.4)
125
+ thread_safe (0.3.6)
126
+ tzinfo (1.2.3)
127
+ thread_safe (~> 0.1)
128
+
129
+ PLATFORMS
130
+ ruby
131
+
132
+ DEPENDENCIES
133
+ appraisal
134
+ cached_resource!
135
+ rails (~> 4.2.0)
136
+ rake
137
+ rspec
138
+
139
+ BUNDLED WITH
140
+ 1.17.1
data/gemfiles/5.0.gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+
7
+ gemspec path: "../"
data/gemfiles/5.0.gemfile.lock ADDED
@@ -0,0 +1,150 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ cached_resource (5.1.1)
5
+ activeresource (>= 4.0)
6
+ activesupport (>= 4.0)
7
+ nilio (>= 1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actioncable (5.0.2)
13
+ actionpack (= 5.0.2)
14
+ nio4r (>= 1.2, < 3.0)
15
+ websocket-driver (~> 0.6.1)
16
+ actionmailer (5.0.2)
17
+ actionpack (= 5.0.2)
18
+ actionview (= 5.0.2)
19
+ activejob (= 5.0.2)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ rails-dom-testing (~> 2.0)
22
+ actionpack (5.0.2)
23
+ actionview (= 5.0.2)
24
+ activesupport (= 5.0.2)
25
+ rack (~> 2.0)
26
+ rack-test (~> 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (5.0.2)
30
+ activesupport (= 5.0.2)
31
+ builder (~> 3.1)
32
+ erubis (~> 2.7.0)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
+ activejob (5.0.2)
36
+ activesupport (= 5.0.2)
37
+ globalid (>= 0.3.6)
38
+ activemodel (5.0.2)
39
+ activesupport (= 5.0.2)
40
+ activemodel-serializers-xml (1.0.1)
41
+ activemodel (> 5.x)
42
+ activerecord (> 5.x)
43
+ activesupport (> 5.x)
44
+ builder (~> 3.1)
45
+ activerecord (5.0.2)
46
+ activemodel (= 5.0.2)
47
+ activesupport (= 5.0.2)
48
+ arel (~> 7.0)
49
+ activeresource (5.0.0)
50
+ activemodel (>= 5.0, < 6)
51
+ activemodel-serializers-xml (~> 1.0)
52
+ activesupport (>= 5.0, < 6)
53
+ activesupport (5.0.2)
54
+ concurrent-ruby (~> 1.0, >= 1.0.2)
55
+ i18n (~> 0.7)
56
+ minitest (~> 5.1)
57
+ tzinfo (~> 1.1)
58
+ appraisal (2.2.0)
59
+ bundler
60
+ rake
61
+ thor (>= 0.14.0)
62
+ arel (7.1.4)
63
+ builder (3.2.3)
64
+ concurrent-ruby (1.0.5)
65
+ diff-lcs (1.3)
66
+ erubis (2.7.0)
67
+ globalid (0.4.0)
68
+ activesupport (>= 4.2.0)
69
+ i18n (0.8.4)
70
+ loofah (2.0.3)
71
+ nokogiri (>= 1.5.9)
72
+ mail (2.6.6)
73
+ mime-types (>= 1.16, < 4)
74
+ method_source (0.8.2)
75
+ mime-types (3.1)
76
+ mime-types-data (~> 3.2015)
77
+ mime-types-data (3.2016.0521)
78
+ mini_portile2 (2.2.0)
79
+ minitest (5.10.2)
80
+ nilio (1.0.0)
81
+ nio4r (2.1.0)
82
+ nokogiri (1.8.0)
83
+ mini_portile2 (~> 2.2.0)
84
+ rack (2.0.3)
85
+ rack-test (0.6.3)
86
+ rack (>= 1.0)
87
+ rails (5.0.2)
88
+ actioncable (= 5.0.2)
89
+ actionmailer (= 5.0.2)
90
+ actionpack (= 5.0.2)
91
+ actionview (= 5.0.2)
92
+ activejob (= 5.0.2)
93
+ activemodel (= 5.0.2)
94
+ activerecord (= 5.0.2)
95
+ activesupport (= 5.0.2)
96
+ bundler (>= 1.3.0, < 2.0)
97
+ railties (= 5.0.2)
98
+ sprockets-rails (>= 2.0.0)
99
+ rails-dom-testing (2.0.3)
100
+ activesupport (>= 4.2.0)
101
+ nokogiri (>= 1.6)
102
+ rails-html-sanitizer (1.0.3)
103
+ loofah (~> 2.0)
104
+ railties (5.0.2)
105
+ actionpack (= 5.0.2)
106
+ activesupport (= 5.0.2)
107
+ method_source
108
+ rake (>= 0.8.7)
109
+ thor (>= 0.18.1, < 2.0)
110
+ rake (12.0.0)
111
+ rspec (3.6.0)
112
+ rspec-core (~> 3.6.0)
113
+ rspec-expectations (~> 3.6.0)
114
+ rspec-mocks (~> 3.6.0)
115
+ rspec-core (3.6.0)
116
+ rspec-support (~> 3.6.0)
117
+ rspec-expectations (3.6.0)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.6.0)
120
+ rspec-mocks (3.6.0)
121
+ diff-lcs (>= 1.2.0, < 2.0)
122
+ rspec-support (~> 3.6.0)
123
+ rspec-support (3.6.0)
124
+ sprockets (3.7.1)
125
+ concurrent-ruby (~> 1.0)
126
+ rack (> 1, < 3)
127
+ sprockets-rails (3.2.0)
128
+ actionpack (>= 4.0)
129
+ activesupport (>= 4.0)
130
+ sprockets (>= 3.0.0)
131
+ thor (0.19.4)
132
+ thread_safe (0.3.6)
133
+ tzinfo (1.2.3)
134
+ thread_safe (~> 0.1)
135
+ websocket-driver (0.6.5)
136
+ websocket-extensions (>= 0.1.0)
137
+ websocket-extensions (0.1.2)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ appraisal
144
+ cached_resource!
145
+ rails (~> 5.0.0)
146
+ rake
147
+ rspec
148
+
149
+ BUNDLED WITH
150
+ 1.17.1
data/gemfiles/5.1.gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 5.1.0"
6
+
7
+ gemspec path: "../"
data/gemfiles/5.1.gemfile.lock ADDED
@@ -0,0 +1,150 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ cached_resource (5.1.1)
5
+ activeresource (>= 4.0)
6
+ activesupport (>= 4.0)
7
+ nilio (>= 1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actioncable (5.1.2)
13
+ actionpack (= 5.1.2)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (~> 0.6.1)
16
+ actionmailer (5.1.2)
17
+ actionpack (= 5.1.2)
18
+ actionview (= 5.1.2)
19
+ activejob (= 5.1.2)
20
+ mail (~> 2.5, >= 2.5.4)
21
+ rails-dom-testing (~> 2.0)
22
+ actionpack (5.1.2)
23
+ actionview (= 5.1.2)
24
+ activesupport (= 5.1.2)
25
+ rack (~> 2.0)
26
+ rack-test (~> 0.6.3)
27
+ rails-dom-testing (~> 2.0)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ actionview (5.1.2)
30
+ activesupport (= 5.1.2)
31
+ builder (~> 3.1)
32
+ erubi (~> 1.4)
33
+ rails-dom-testing (~> 2.0)
34
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
+ activejob (5.1.2)
36
+ activesupport (= 5.1.2)
37
+ globalid (>= 0.3.6)
38
+ activemodel (5.1.2)
39
+ activesupport (= 5.1.2)
40
+ activemodel-serializers-xml (1.0.1)
41
+ activemodel (> 5.x)
42
+ activerecord (> 5.x)
43
+ activesupport (> 5.x)
44
+ builder (~> 3.1)
45
+ activerecord (5.1.2)
46
+ activemodel (= 5.1.2)
47
+ activesupport (= 5.1.2)
48
+ arel (~> 8.0)
49
+ activeresource (5.0.0)
50
+ activemodel (>= 5.0, < 6)
51
+ activemodel-serializers-xml (~> 1.0)
52
+ activesupport (>= 5.0, < 6)
53
+ activesupport (5.1.2)
54
+ concurrent-ruby (~> 1.0, >= 1.0.2)
55
+ i18n (~> 0.7)
56
+ minitest (~> 5.1)
57
+ tzinfo (~> 1.1)
58
+ appraisal (2.2.0)
59
+ bundler
60
+ rake
61
+ thor (>= 0.14.0)
62
+ arel (8.0.0)
63
+ builder (3.2.3)
64
+ concurrent-ruby (1.0.5)
65
+ diff-lcs (1.3)
66
+ erubi (1.6.0)
67
+ globalid (0.4.0)
68
+ activesupport (>= 4.2.0)
69
+ i18n (0.8.4)
70
+ loofah (2.0.3)
71
+ nokogiri (>= 1.5.9)
72
+ mail (2.6.6)
73
+ mime-types (>= 1.16, < 4)
74
+ method_source (0.8.2)
75
+ mime-types (3.1)
76
+ mime-types-data (~> 3.2015)
77
+ mime-types-data (3.2016.0521)
78
+ mini_portile2 (2.2.0)
79
+ minitest (5.10.2)
80
+ nilio (1.0.0)
81
+ nio4r (2.1.0)
82
+ nokogiri (1.8.0)
83
+ mini_portile2 (~> 2.2.0)
84
+ rack (2.0.3)
85
+ rack-test (0.6.3)
86
+ rack (>= 1.0)
87
+ rails (5.1.2)
88
+ actioncable (= 5.1.2)
89
+ actionmailer (= 5.1.2)
90
+ actionpack (= 5.1.2)
91
+ actionview (= 5.1.2)
92
+ activejob (= 5.1.2)
93
+ activemodel (= 5.1.2)
94
+ activerecord (= 5.1.2)
95
+ activesupport (= 5.1.2)
96
+ bundler (>= 1.3.0, < 2.0)
97
+ railties (= 5.1.2)
98
+ sprockets-rails (>= 2.0.0)
99
+ rails-dom-testing (2.0.3)
100
+ activesupport (>= 4.2.0)
101
+ nokogiri (>= 1.6)
102
+ rails-html-sanitizer (1.0.3)
103
+ loofah (~> 2.0)
104
+ railties (5.1.2)
105
+ actionpack (= 5.1.2)
106
+ activesupport (= 5.1.2)
107
+ method_source
108
+ rake (>= 0.8.7)
109
+ thor (>= 0.18.1, < 2.0)
110
+ rake (12.0.0)
111
+ rspec (3.6.0)
112
+ rspec-core (~> 3.6.0)
113
+ rspec-expectations (~> 3.6.0)
114
+ rspec-mocks (~> 3.6.0)
115
+ rspec-core (3.6.0)
116
+ rspec-support (~> 3.6.0)
117
+ rspec-expectations (3.6.0)
118
+ diff-lcs (>= 1.2.0, < 2.0)
119
+ rspec-support (~> 3.6.0)
120
+ rspec-mocks (3.6.0)
121
+ diff-lcs (>= 1.2.0, < 2.0)
122
+ rspec-support (~> 3.6.0)
123
+ rspec-support (3.6.0)
124
+ sprockets (3.7.1)
125
+ concurrent-ruby (~> 1.0)
126
+ rack (> 1, < 3)
127
+ sprockets-rails (3.2.0)
128
+ actionpack (>= 4.0)
129
+ activesupport (>= 4.0)
130
+ sprockets (>= 3.0.0)
131
+ thor (0.19.4)
132
+ thread_safe (0.3.6)
133
+ tzinfo (1.2.3)
134
+ thread_safe (~> 0.1)
135
+ websocket-driver (0.6.5)
136
+ websocket-extensions (>= 0.1.0)
137
+ websocket-extensions (0.1.2)
138
+
139
+ PLATFORMS
140
+ ruby
141
+
142
+ DEPENDENCIES
143
+ appraisal
144
+ cached_resource!
145
+ rails (~> 5.1.0)
146
+ rake
147
+ rspec
148
+
149
+ BUNDLED WITH
150
+ 1.17.1
data/gemfiles/Gemfile.rails-3.2.x DELETED
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec :path => "../"
4
-
5
- gem "activeresource", "~> 3.2"
6
- gem "activesupport", "~> 3.2"
7
-
8
-
data/lib/cached_resource.rb CHANGED
@@ -1,7 +1,9 @@
1
1
require 'ostruct'
2
2
3
3
require 'nilio'
4
+ require 'active_support/cache'
4
5
require 'active_support/concern'
6
+ require 'active_support/logger'
5
7
require 'cached_resource/cached_resource'
6
8
require 'cached_resource/configuration'
7
9
require 'cached_resource/caching'
data/lib/cached_resource/cached_resource.rb CHANGED
@@ -31,8 +31,8 @@ module CachedResource
31
31
# self.cached_resource = CachedResource::Configuration.new(options={})
32
32
def inherited(child)
33
33
child.cached_resource = self.cached_resource if defined?(@cached_resource)
34
+ super
34
35
end
35
36
end
36
-
37
37
end
38
- end
38
+ end
data/lib/cached_resource/caching.rb CHANGED
@@ -6,7 +6,8 @@ module CachedResource
6
6
7
7
included do
8
8
class << self
9
- alias_method_chain :find, :cache
9
+ alias_method :find_without_cache, :find
10
+ alias_method :find, :find_with_cache
10
11
end
11
12
end
12
13
@@ -83,13 +84,20 @@ module CachedResource
83
84
84
85
# Read a entry from the cache for the given key.
85
86
def cache_read(key)
86
- object = cached_resource.cache.read(key).try do |cache|
87
- if cache.is_a? Enumerable
88
- restored = cache.map { |record| full_dup(record) }
89
- next restored unless respond_to?(:collection_parser)
90
- collection_parser.new(restored)
91
- else
92
- full_dup(cache)
87
+ object = cached_resource.cache.read(key).try do |json_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
93
101
end
94
102
end
95
103
object && cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} READ #{key}")
@@ -98,7 +106,7 @@ module CachedResource
98
106
99
107
# Write an entry to the cache for the given key and value.
100
108
def cache_write(key, object)
101
- result = cached_resource.cache.write(key, object, :race_condition_ttl => cached_resource.race_condition_ttl, :expires_in => cached_resource.generate_ttl)
109
+ result = cached_resource.cache.write(key, object_to_json(object), :race_condition_ttl => cached_resource.race_condition_ttl, :expires_in => cached_resource.generate_ttl)
102
110
result && cached_resource.logger.info("#{CachedResource::Configuration::LOGGER_PREFIX} WRITE #{key}")
103
111
result
104
112
end
@@ -123,6 +131,24 @@ module CachedResource
123
131
end
124
132
end
125
133
134
+ def json_to_object(json)
135
+ if json.is_a? Array
136
+ json.map { |attrs|
137
+ self.new(attrs[:object], attrs[:persistence]) }
138
+ else
139
+ self.new(json[:object], json[:persistence])
140
+ end
141
+ end
142
+
143
+ def object_to_json(object)
144
+ if object.is_a? Enumerable
145
+ object.map { |o| { :object => o, :persistence => o.persisted? } }.to_json
146
+ elsif object.nil?
147
+ nil.to_json
148
+ else
149
+ { :object => object, :persistence => object.persisted? }.to_json
150
+ end
151
+ end
126
152
end
127
153
end
128
154
end
data/lib/cached_resource/configuration.rb CHANGED
@@ -6,12 +6,8 @@ module CachedResource
6
6
# default or fallback cache without rails
7
7
CACHE = ActiveSupport::Cache::MemoryStore.new
8
8
9
- # default of fallback logger without rails
10
- LOGGER = if defined?(ActiveSupport::Logger)
9
+ # default or fallback logger without rails
10
+ LOGGER = ActiveSupport::Logger.new(NilIO.instance)
11
- ActiveSupport::Logger.new(NilIO.instance)
12
- else
13
- ActiveSupport::BufferedLogger.new(NilIO.instance)
14
- end
15
11
16
12
# prefix for log messages
17
13
LOGGER_PREFIX = "[cached_resource]"
@@ -26,7 +22,7 @@ module CachedResource
26
22
# :collection_synchronize, default: false,
27
23
# :collection_arguments, default: [:all]
28
24
# :cache, default: Rails.cache or ActiveSupport::Cache::MemoryStore.new,
29
- # :logger, default: Rails.logger or ActiveSupport::BufferedLogger.new(NilIO.new)
25
+ # :logger, default: Rails.logger or ActiveSupport::Logger.new(NilIO.new)
30
26
def initialize(options={})
31
27
super({
32
28
:enabled => true,
data/lib/cached_resource/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
module CachedResource
2
- VERSION = "4.2.0"
2
+ VERSION = "5.1.2"
3
3
end
data/spec/cached_resource/cached_resource_spec.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CachedResource do
4
+ before do
5
+ class BaseThing < ActiveResource::Base
6
+ end
7
+
8
+ class FirstChildThing < BaseThing
9
+ self.site = 'http://api.first-child-thing.com'
10
+ cached_resource
11
+ end
12
+
13
+ class SecondChildThing < BaseThing
14
+ self.site = 'http://api.second-child-thing.com'
15
+ end
16
+ end
17
+
18
+ after do
19
+ [:BaseThing, :FirstChildThing, :SecondChildThing].each do |klass|
20
+ Object.send(:remove_const, klass)
21
+ end
22
+ end
23
+
24
+ describe '.inherited' do
25
+ it 'should include descendants when calling .descendants' do
26
+ BaseThing.descendants.sort_by { |klass| klass.name }.should == [FirstChildThing, SecondChildThing]
27
+ end
28
+ end
29
+ end
data/spec/cached_resource/caching_spec.rb CHANGED
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
3
3
describe CachedResource do
4
4
5
+ def read_from_cache(key)
6
+ Thing.send(:cache_read, key)
7
+ end
8
+
5
9
before(:each) do
6
10
class Thing < ActiveResource::Base
7
11
self.site = "http://api.thing.com"
@@ -19,6 +23,7 @@ describe CachedResource do
19
23
@other_thing_json = @other_thing.to_json
20
24
@string_thing_json = @string_thing.to_json
21
25
@other_string_thing_json = @other_string_thing.to_json
26
+ @nil_thing = nil.to_json
22
27
end
23
28
24
29
after(:each) do
@@ -38,32 +43,40 @@ describe CachedResource do
38
43
mock.get "/things/1.json", {}, @thing_json
39
44
mock.get "/things/1.json?foo=bar", {}, @thing_json
40
45
mock.get "/things/fded.json", {}, @string_thing_json
46
+ mock.get "/things.json?name=42", {}, @nil_thing, 404
41
47
end
42
48
end
43
49
44
50
it "should cache a response" do
45
51
result = Thing.find(1)
46
- Thing.cached_resource.cache.read("thing/1").should == result
52
+
53
+ read_from_cache("thing/1").should == result
54
+ end
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
47
59
end
48
60
49
61
it "should cache a response for a string primary key" do
50
62
result = Thing.find("fded")
51
- Thing.cached_resource.cache.read("thing/fded").should == result
63
+ read_from_cache("thing/fded").should == result
52
64
end
53
65
54
66
it "should cache without whitespace in keys" do
55
67
result = Thing.find(1, :from => 'path', :params => { :foo => 'bar' })
56
- Thing.cached_resource.cache.read('thing/1/{:from=>"path",:params=>{:foo=>"bar"}}').should == result
68
+ read_from_cache('thing/1/{:from=>"path",:params=>{:foo=>"bar"}}').should == result
57
69
end
58
70
59
71
it "should empty the cache when clear_cache is called" do
60
72
result = Thing.find(1)
61
73
Thing.clear_cache
62
- Thing.cached_resource.cache.read("thing/1").should == nil
74
+ read_from_cache("thing/1").should == nil
63
75
end
64
76
65
77
it "should cache a response with the same persistence" do
66
78
result1 = Thing.find(1)
79
+ result1.persisted?.should be true
67
80
result2 = Thing.find(1)
68
81
result1.persisted?.should == result2.persisted?
69
82
end
@@ -108,7 +121,7 @@ describe CachedResource do
108
121
# make a request
109
122
Thing.find(1)
110
123
# get the cached result of the request
111
- old_result = Thing.cached_resource.cache.read("thing/1")
124
+ old_result = read_from_cache("thing/1")
112
125
113
126
# change the response
114
127
ActiveResource::HttpMock.reset!
@@ -117,7 +130,7 @@ describe CachedResource do
117
130
end
118
131
119
132
Thing.find(1, :reload => true)
120
- new_result = Thing.cached_resource.cache.read("thing/1")
133
+ new_result = read_from_cache("thing/1")
121
134
# since active resources are equal if and only if they
122
135
# are the same object or an instance of the same class,
123
136
# not new?, and have the same id.
@@ -156,7 +169,7 @@ describe CachedResource do
156
169
shared_examples "collection_return_type" do
157
170
if ActiveResource::VERSION::MAJOR >= 4
158
171
it "should return an ActiveResource::Collection" do
159
- cached = Thing.cached_resource.cache.read("thing/all")
172
+ cached = read_from_cache("thing/all")
160
173
cached.should be_instance_of(ActiveResource::Collection)
161
174
end
162
175
@@ -165,12 +178,12 @@ describe CachedResource do
165
178
class CustomCollection < ActiveResource::Collection; end
166
179
Thing.collection_parser = CustomCollection
167
180
Thing.all
168
- cached = Thing.cached_resource.cache.read("thing/all")
181
+ cached = read_from_cache("thing/all")
169
182
cached.should be_instance_of(CustomCollection)
170
183
end
171
184
else
172
185
it "should return an Array" do
173
- cached = Thing.cached_resource.cache.read("thing/all")
186
+ cached = read_from_cache("thing/all")
174
187
cached.should be_instance_of(Array)
175
188
end
176
189
end
@@ -222,8 +235,8 @@ describe CachedResource do
222
235
shared_examples "collection_cache_clearing" do
223
236
it "should empty the cache when clear_cache is called" do
224
237
Thing.clear_cache
225
- Thing.cached_resource.cache.read("thing/all").should == nil
226
- Thing.cached_resource.cache.read("thing/1").should == nil
238
+ read_from_cache("thing/all").should == nil
239
+ read_from_cache("thing/1").should == nil
227
240
end
228
241
229
242
end
@@ -254,8 +267,8 @@ describe CachedResource do
254
267
# only the all request should have been made
255
268
ActiveResource::HttpMock.requests.length.should == 1
256
269
# the result should be cached with the appropriate key
257
- Thing.cached_resource.cache.read("thing/1").should == result
258
- Thing.cached_resource.cache.read("thing/fded").should == string_result
270
+ read_from_cache("thing/1").should == result
271
+ read_from_cache("thing/fded").should == string_result
259
272
end
260
273
261
274
include_examples "collection_cache_clearing"
@@ -274,11 +287,11 @@ describe CachedResource do
274
287
Thing.all(:reload => true)
275
288
# get the updated result, read from the cache
276
289
result = Thing.find(1)
277
- Thing.cached_resource.cache.read("thing/all")[0].should == result
278
- Thing.cached_resource.cache.read("thing/all")[0].name.should == result.name
290
+ read_from_cache("thing/all")[0].should == result
291
+ read_from_cache("thing/all")[0].name.should == result.name
279
292
string_result = Thing.find("fded")
280
- Thing.cached_resource.cache.read("thing/all")[1].should == string_result
281
- Thing.cached_resource.cache.read("thing/all")[1].name.should == string_result.name
293
+ read_from_cache("thing/all")[1].should == string_result
294
+ read_from_cache("thing/all")[1].name.should == string_result.name
282
295
end
283
296
284
297
it "should update the collection when an individual request is reloaded" do
@@ -291,11 +304,11 @@ describe CachedResource do
291
304
292
305
# reload the individual
293
306
result = Thing.find(1, :reload => true)
294
- Thing.cached_resource.cache.read("thing/all")[0].should == result
295
- Thing.cached_resource.cache.read("thing/all")[0].name.should == result.name
307
+ read_from_cache("thing/all")[0].should == result
308
+ read_from_cache("thing/all")[0].name.should == result.name
296
309
string_result = Thing.find("fded", :reload => true)
297
- Thing.cached_resource.cache.read("thing/all")[1].should == string_result
298
- Thing.cached_resource.cache.read("thing/all")[1].name.should == string_result.name
310
+ read_from_cache("thing/all")[1].should == string_result
311
+ read_from_cache("thing/all")[1].name.should == string_result.name
299
312
end
300
313
301
314
it "should update both the collection and the member cache entries when a subset of the collection is retrieved" do
@@ -312,20 +325,20 @@ describe CachedResource do
312
325
# make a request for a subset of the "mother" collection
313
326
result = Thing.find(:all, :params => {:name => "Ari"})
314
327
# the collection should be updated to reflect the server change
315
- Thing.cached_resource.cache.read("thing/all")[0].should == result[0]
316
- Thing.cached_resource.cache.read("thing/all")[0].name.should == result[0].name
328
+ read_from_cache("thing/all")[0].should == result[0]
329
+ read_from_cache("thing/all")[0].name.should == result[0].name
317
330
# the individual should be updated to reflect the server change
318
- Thing.cached_resource.cache.read("thing/1").should == result[0]
319
- Thing.cached_resource.cache.read("thing/1").name.should == result[0].name
331
+ read_from_cache("thing/1").should == result[0]
332
+ read_from_cache("thing/1").name.should == result[0].name
320
333
321
334
# make a request for a subset of the "mother" collection
322
335
result = Thing.find(:all, :params => {:name => "Lon"})
323
336
# the collection should be updated to reflect the server change
324
- Thing.cached_resource.cache.read("thing/all")[1].should == result[0]
325
- Thing.cached_resource.cache.read("thing/all")[1].name.should == result[0].name
337
+ read_from_cache("thing/all")[1].should == result[0]
338
+ read_from_cache("thing/all")[1].name.should == result[0].name
326
339
# the individual should be updated to reflect the server change
327
- Thing.cached_resource.cache.read("thing/fded").should == result[0]
328
- Thing.cached_resource.cache.read("thing/fded").name.should == result[0].name
340
+ read_from_cache("thing/fded").should == result[0]
341
+ read_from_cache("thing/fded").name.should == result[0].name
329
342
end
330
343
331
344
it "should maintain the order of the collection when updating it" do
@@ -407,12 +420,12 @@ describe CachedResource do
407
420
# reload the individual
408
421
result = Thing.find(1, :reload => true)
409
422
# the ids are the same, but the names should be different
410
- Thing.cached_resource.cache.read("thing/all")[0].name.should_not == result.name
423
+ read_from_cache("thing/all")[0].name.should_not == result.name
411
424
412
425
# reload the individual
413
426
string_result = Thing.find("fded", :reload => true)
414
427
# the ids are the same, but the names should be different
415
- Thing.cached_resource.cache.read("thing/all")[1].name.should_not == string_result.name
428
+ read_from_cache("thing/all")[1].name.should_not == string_result.name
416
429
end
417
430
end
418
431
@@ -452,12 +465,12 @@ describe CachedResource do
452
465
453
466
it "should cache a response" do
454
467
result = Thing.find(1)
455
- Thing.cached_resource.cache.read("thing/1").should == result
468
+ read_from_cache("thing/1").should == result
456
469
end
457
470
458
471
it "should cache a response for a string primary key" do
459
472
result = Thing.find("fded")
460
- Thing.cached_resource.cache.read("thing/fded").should == result
473
+ read_from_cache("thing/fded").should == result
461
474
end
462
475
463
476
it "should always remake the request" do
@@ -476,7 +489,7 @@ describe CachedResource do
476
489
477
490
it "should rewrite the cache for each request" do
478
491
Thing.find(1)
479
- old_result = Thing.cached_resource.cache.read("thing/1")
492
+ old_result = read_from_cache("thing/1")
480
493
481
494
# change the response
482
495
ActiveResource::HttpMock.reset!
@@ -485,7 +498,7 @@ describe CachedResource do
485
498
end
486
499
487
500
Thing.find(1)
488
- new_result = Thing.cached_resource.cache.read("thing/1")
501
+ new_result = read_from_cache("thing/1")
489
502
# since active resources are equal if and only if they
490
503
# are the same object or an instance of the same class,
491
504
# not new?, and have the same id.
@@ -494,7 +507,7 @@ describe CachedResource do
494
507
495
508
it "should rewrite the cache for each request for a string primary key" do
496
509
Thing.find("fded")
497
- old_result = Thing.cached_resource.cache.read("thing/fded")
510
+ old_result = read_from_cache("thing/fded")
498
511
499
512
# change the response
500
513
ActiveResource::HttpMock.reset!
@@ -503,7 +516,7 @@ describe CachedResource do
503
516
end
504
517
505
518
Thing.find("fded")
506
- new_result = Thing.cached_resource.cache.read("thing/fded")
519
+ new_result = read_from_cache("thing/fded")
507
520
# since active resources are equal if and only if they
508
521
# are the same object or an instance of the same class,
509
522
# not new?, and have the same id.
metadata CHANGED
@@ -1,115 +1,155 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
name: cached_resource
3
- version: !ruby/object:Gem::Version
4
- version: 4.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.1.2
5
5
platform: ruby
6
- authors:
6
+ authors:
7
7
- Morgan Brown
8
8
autorequire:
9
9
bindir: bin
10
10
cert_chain: []
11
-
12
- date: 2015-12-03 00:00:00 Z
13
- dependencies:
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
- - !ruby/object:Gem::Dependency
15
- name: rake
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - &id005
20
- - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
23
- type: :runtime
24
- version_requirements: *id001
25
- - !ruby/object:Gem::Dependency
26
14
name: activeresource
27
- prerelease: false
28
- requirement: &id002 !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
29
- requirements:
30
17
- - ">="
31
- - !ruby/object:Gem::Version
32
- version: "3.2"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
33
20
type: :runtime
34
- version_requirements: *id002
35
- - !ruby/object:Gem::Dependency
36
- name: activesupport
37
21
prerelease: false
38
- requirement: &id003 !ruby/object:Gem::Requirement
39
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
40
31
- - ">="
41
- - !ruby/object:Gem::Version
42
- version: "3.2"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
43
34
type: :runtime
44
- version_requirements: *id003
45
- - !ruby/object:Gem::Dependency
46
- name: nilio
47
35
prerelease: false
48
- requirement: &id004 !ruby/object:Gem::Requirement
49
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nilio
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
50
45
- - ">="
51
- - !ruby/object:Gem::Version
52
- version: "1.0"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
53
48
type: :runtime
54
- version_requirements: *id004
55
- - !ruby/object:Gem::Dependency
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
56
70
name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
57
77
prerelease: false
58
- requirement: &id006 !ruby/object:Gem::Requirement
59
- requirements:
60
- - *id005
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: appraisal
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
61
90
type: :development
62
- version_requirements: *id006
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
63
97
description: Enables request-based caching for ActiveResource
64
98
email: brown.mhg@gmail.com
65
99
executables: []
66
-
67
100
extensions: []
68
-
69
101
extra_rdoc_files: []
70
-
71
- files:
72
- - .gitignore
73
- - .rspec
74
- - .travis.yml
102
+ files:
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".travis.yml"
106
+ - Appraisals
75
107
- Gemfile
76
- - MIT-LICENSE
108
+ - LICENSE
77
109
- README.md
78
110
- Rakefile
79
111
- cached_resource.gemspec
80
- - gemfiles/Gemfile.rails-3.2.x
112
+ - gemfiles/4.2.gemfile
113
+ - gemfiles/4.2.gemfile.lock
114
+ - gemfiles/5.0.gemfile
115
+ - gemfiles/5.0.gemfile.lock
116
+ - gemfiles/5.1.gemfile
117
+ - gemfiles/5.1.gemfile.lock
81
118
- lib/cached_resource.rb
82
119
- lib/cached_resource/cached_resource.rb
83
120
- lib/cached_resource/caching.rb
84
121
- lib/cached_resource/configuration.rb
85
122
- lib/cached_resource/version.rb
123
+ - spec/cached_resource/cached_resource_spec.rb
86
124
- spec/cached_resource/caching_spec.rb
87
125
- spec/cached_resource/configuration_spec.rb
88
126
- spec/spec_helper.rb
89
- homepage: http://github.com/Ahsizara/cached_resource
90
- licenses: []
91
-
127
+ homepage: https://github.com/mhgbrown/cached_resource
128
+ licenses:
129
+ - MIT
92
130
metadata: {}
93
-
94
131
post_install_message:
95
132
rdoc_options: []
96
-
133
+ require_paths:
97
- require_paths:
98
134
- lib
99
- required_ruby_version: !ruby/object:Gem::Requirement
100
- requirements:
101
- - *id005
102
- required_rubygems_version: !ruby/object:Gem::Requirement
103
- requirements:
104
- - *id005
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
105
145
requirements: []
106
-
107
146
rubyforge_project:
108
- rubygems_version: 2.0.14
147
+ rubygems_version: 2.7.6
109
148
signing_key:
110
149
specification_version: 4
111
150
summary: Caching for ActiveResource
112
- test_files:
151
+ test_files:
152
+ - spec/cached_resource/cached_resource_spec.rb
113
153
- spec/cached_resource/caching_spec.rb
114
154
- spec/cached_resource/configuration_spec.rb
115
155
- spec/spec_helper.rb