active_remote-cached 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -16
- data/active_remote-cached.gemspec +1 -1
- data/lib/active_remote-cached.rb +1 -262
- data/lib/active_remote/cached.rb +269 -0
- data/lib/{active_remote-cached → active_remote/cached}/cache.rb +0 -0
- data/lib/active_remote/cached/railtie.rb +14 -0
- data/lib/{active_remote-cached → active_remote/cached}/version.rb +1 -1
- data/spec/{cache_spec.rb → active_remote/cached/cache_spec.rb} +0 -0
- data/spec/{cached_delete_methods_spec.rb → active_remote/cached_delete_methods_spec.rb} +0 -0
- data/spec/{cached_exist_methods_spec.rb → active_remote/cached_exist_methods_spec.rb} +0 -0
- data/spec/{cached_find_methods_spec.rb → active_remote/cached_find_methods_spec.rb} +0 -0
- data/spec/{cached_search_methods_spec.rb → active_remote/cached_search_methods_spec.rb} +0 -0
- metadata +31 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ab07ab8e11e7520b6bfb6d309943f8824076362
|
4
|
+
data.tar.gz: ad6a3abff29c918cd16e9dc94a283f222cfdb606
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcecd3db779daa85deb56636edd9511c670cca9c079a02f861a09e1547e3758af0f5423471bce501d7156d51267dd845dff5b76e6884966ef2679a8cfc7f442a
|
7
|
+
data.tar.gz: 1811c6219eb8123a54dc4e6a95bd75952fd71a28ef70038b57f5a5b6f50d9073a4f67d7f0bb4b3873b45da28d4e69f3fadf471216347551bcb0774bf1759f075
|
data/README.md
CHANGED
@@ -18,38 +18,76 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Defining cache finders
|
22
|
+
|
23
|
+
Include `::ActiveRemote::Cached` into your ActiveRemote models that can support cached finders*
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class Customer < ::ActiveRemote::Base
|
27
|
+
include ::ActiveRemote::Cached
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
_*This is already done for you in Rails_
|
32
|
+
|
33
|
+
Then declare some cache finder methods. Cached finders can be defined for individual fields or defined as composites for mulitple fields
|
22
34
|
|
23
35
|
```ruby
|
24
|
-
|
25
|
-
|
36
|
+
class Customer < ::ActiveRemote::Base
|
37
|
+
# Create a cached finder for id
|
38
|
+
cached_finders_for :id
|
26
39
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
40
|
+
# Create a composite cached finder for name and email
|
41
|
+
cached_finders_for [:name, :email]
|
42
|
+
end
|
31
43
|
```
|
32
44
|
|
33
45
|
Now that you have a model that has cached finders on it you can use the `cached_search`, `cached_find`, or dynamic cached finder methods on the model to use the cache before you issue the AR search/find method.
|
34
46
|
|
35
47
|
```ruby
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
48
|
+
customer = ::Customer.cached_find_by_id(1) # => <Customer id=1>
|
49
|
+
customer = ::Customer.cached_find(:id => 1) # => <Customer id=1>
|
50
|
+
customer = ::Customer.cached_search_by_id(1) # => [ <Customer id=1> ]
|
51
|
+
customer = ::Customer.cached_search(:id => 1) # => [ <Customer id=1> ]
|
40
52
|
```
|
41
53
|
|
42
54
|
```ruby
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
# All permutations of "complex" dynamic finders are defined
|
56
|
+
customer = ::Customer.cached_find_by_name_and_email("name", "email") # => <Customer id=1>
|
57
|
+
customer = ::Customer.cached_find_by_email_and_name("email", "name") # => <Customer id=1>
|
58
|
+
|
59
|
+
# Only declared finders are defined
|
60
|
+
customer = ::Customer.cached_find_by_name("name") # => NoMethodError
|
61
|
+
```
|
62
|
+
|
63
|
+
### Configuring the cache provider
|
64
|
+
|
65
|
+
ActiveRemote::Cached relies on an ActiveSupport::Cache-compatible cache provider. The cache is initialized with a simple memory store (defaults to 32MB), but can be overridden via `ActiveRemote::Cached.cache`:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
ActiveRemote::Cached.cache(Your::ActiveSupport::Cache::Compatible::Provider.new)
|
69
|
+
```
|
70
|
+
|
71
|
+
In Rails apps, the memory store is replaced the whatever Rails is using as it's cache store.
|
46
72
|
|
47
|
-
|
48
|
-
|
73
|
+
#### Default options
|
74
|
+
|
75
|
+
The default cache options used when interacting with the cache can be specified via `ActiveRemote::Cached.default_options`:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
ActiveRemote::Cached.default_options(:expires_in => 1.hour)
|
49
79
|
```
|
50
80
|
|
81
|
+
In Rails apps, the :race_condition_ttl option defaults to 5 seconds.
|
82
|
+
|
83
|
+
#### Local overrides
|
84
|
+
|
51
85
|
Each finder as takes an optional options hash that will override the options passed to the caching provider (override from the global defaults setup for ActiveRemote::Cached)
|
52
86
|
|
87
|
+
```ruby
|
88
|
+
customer = ::Customer.cached_find_by_id(1, :expires_in => 15.minutes)
|
89
|
+
```
|
90
|
+
|
53
91
|
## Contributing
|
54
92
|
|
55
93
|
1. Fork it
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'active_remote
|
4
|
+
require 'active_remote/cached/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "active_remote-cached"
|
data/lib/active_remote-cached.rb
CHANGED
@@ -1,262 +1 @@
|
|
1
|
-
require "
|
2
|
-
require "active_support/core_ext/array/extract_options"
|
3
|
-
require "active_remote-cached/version"
|
4
|
-
require "active_remote-cached/cache"
|
5
|
-
|
6
|
-
module ActiveRemote
|
7
|
-
module Cached
|
8
|
-
extend ::ActiveSupport::Concern
|
9
|
-
|
10
|
-
def self.cache(cache_provider = nil)
|
11
|
-
if cache_provider
|
12
|
-
@cache_provider = ::ActiveRemote::Cached::Cache.new(cache_provider)
|
13
|
-
end
|
14
|
-
|
15
|
-
@cache_provider
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.default_options(options = nil)
|
19
|
-
if options
|
20
|
-
@default_options = options
|
21
|
-
end
|
22
|
-
|
23
|
-
@default_options || {}
|
24
|
-
end
|
25
|
-
|
26
|
-
module ClassMethods
|
27
|
-
|
28
|
-
def cached_finders_for(*cached_finder_keys)
|
29
|
-
options = cached_finder_keys.extract_options!
|
30
|
-
|
31
|
-
cached_finder_keys.each do |cached_finder_key|
|
32
|
-
_create_cached_finder_for(cached_finder_key, options)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def cached_finders(*keys)
|
37
|
-
cached_finders_for(*keys)
|
38
|
-
end
|
39
|
-
|
40
|
-
def cached_find(argument_hash, options = {})
|
41
|
-
method_name = _cached_find_method_name(argument_hash.keys)
|
42
|
-
arguments = argument_hash.values
|
43
|
-
|
44
|
-
if block_given?
|
45
|
-
__send__(method_name, *arguments, options) do
|
46
|
-
yield
|
47
|
-
end
|
48
|
-
else
|
49
|
-
__send__(method_name, *arguments, options)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def cached_search(argument_hash, options = {})
|
54
|
-
method_name = _cached_search_method_name(argument_hash.keys)
|
55
|
-
arguments = argument_hash.values
|
56
|
-
|
57
|
-
if block_given?
|
58
|
-
__send__(method_name, *arguments, options) do
|
59
|
-
yield
|
60
|
-
end
|
61
|
-
else
|
62
|
-
__send__(method_name, *arguments, options)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
# Underscored Methods
|
68
|
-
#
|
69
|
-
def _create_cached_finder_for(cached_finder_key, options = {})
|
70
|
-
cached_finder_key_set = [ cached_finder_key ].flatten.sort
|
71
|
-
|
72
|
-
##
|
73
|
-
# Run each permutation of the arguments passed in
|
74
|
-
# and define each finder/searcher
|
75
|
-
#
|
76
|
-
cached_finder_key_set.permutation do |arguments|
|
77
|
-
delete_method_name = _cached_delete_method_name(arguments)
|
78
|
-
exist_find_method_name = _cached_exist_find_method_name(arguments)
|
79
|
-
exist_search_method_name = _cached_exist_search_method_name(arguments)
|
80
|
-
find_method_name = _cached_find_method_name(arguments)
|
81
|
-
search_method_name = _cached_search_method_name(arguments)
|
82
|
-
|
83
|
-
unless self.respond_to?(delete_method_name)
|
84
|
-
_define_cached_delete_method(delete_method_name, arguments)
|
85
|
-
end
|
86
|
-
|
87
|
-
unless self.respond_to?(exist_find_method_name)
|
88
|
-
_define_cached_exist_find_method(exist_find_method_name, arguments)
|
89
|
-
end
|
90
|
-
|
91
|
-
unless self.respond_to?(exist_search_method_name)
|
92
|
-
_define_cached_exist_search_method(exist_search_method_name, arguments)
|
93
|
-
end
|
94
|
-
|
95
|
-
unless self.respond_to?(find_method_name)
|
96
|
-
_define_cached_find_method(find_method_name, arguments)
|
97
|
-
end
|
98
|
-
|
99
|
-
unless self.respond_to?(search_method_name)
|
100
|
-
_define_cached_search_method(search_method_name, arguments)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def _cached_delete_method_name(arguments)
|
106
|
-
"cached_delete_by_#{arguments.join('_and_')}"
|
107
|
-
end
|
108
|
-
|
109
|
-
def _cached_exist_find_method_name(arguments)
|
110
|
-
"cached_exist_find_by_#{arguments.join('_and_')}"
|
111
|
-
end
|
112
|
-
|
113
|
-
def _cached_exist_search_method_name(arguments)
|
114
|
-
"cached_exist_search_by_#{arguments.join('_and_')}"
|
115
|
-
end
|
116
|
-
|
117
|
-
def _cached_find_method_name(arguments)
|
118
|
-
"cached_find_by_#{arguments.join('_and_')}"
|
119
|
-
end
|
120
|
-
|
121
|
-
def _cached_search_method_name(arguments)
|
122
|
-
"cached_search_by_#{arguments.join('_and_')}"
|
123
|
-
end
|
124
|
-
|
125
|
-
def _define_cached_delete_method(method_name, *method_arguments)
|
126
|
-
method_arguments.flatten!
|
127
|
-
expanded_method_args = method_arguments.join(",")
|
128
|
-
sorted_method_args = method_arguments.sort.join(",")
|
129
|
-
|
130
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
131
|
-
# def self.cached_delete_by_user_guid(user_guid, options = {})
|
132
|
-
# ::ActiveRemote::Cached.cache.delete([name, user_guid])
|
133
|
-
# end
|
134
|
-
def self.#{method_name}(#{expanded_method_args}, options = {})
|
135
|
-
::ActiveRemote::Cached.cache.delete([name, "#search", #{sorted_method_args}])
|
136
|
-
::ActiveRemote::Cached.cache.delete([name, "#find", #{sorted_method_args}])
|
137
|
-
end
|
138
|
-
RUBY
|
139
|
-
end
|
140
|
-
|
141
|
-
def _define_cached_exist_find_method(method_name, *method_arguments)
|
142
|
-
method_arguments.flatten!
|
143
|
-
expanded_method_args = method_arguments.join(",")
|
144
|
-
sorted_method_args = method_arguments.sort.join(",")
|
145
|
-
|
146
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
147
|
-
# def self.cached_exist_find_by_user_guid(user_guid, options = {})
|
148
|
-
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
149
|
-
# end
|
150
|
-
def self.#{method_name}(#{expanded_method_args}, options = {})
|
151
|
-
::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
|
152
|
-
end
|
153
|
-
RUBY
|
154
|
-
|
155
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
156
|
-
# def self.cached_exist_find_by_user_guid?(user_guid, options = {})
|
157
|
-
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
158
|
-
# end
|
159
|
-
def self.#{method_name}?(#{expanded_method_args}, options = {})
|
160
|
-
::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
|
161
|
-
end
|
162
|
-
RUBY
|
163
|
-
end
|
164
|
-
|
165
|
-
def _define_cached_exist_search_method(method_name, *method_arguments)
|
166
|
-
method_arguments.flatten!
|
167
|
-
expanded_method_args = method_arguments.join(",")
|
168
|
-
sorted_method_args = method_arguments.sort.join(",")
|
169
|
-
|
170
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
171
|
-
# def self.cached_exist_search_by_user_guid(user_guid, options = {})
|
172
|
-
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
173
|
-
# end
|
174
|
-
def self.#{method_name}(#{expanded_method_args}, options = {})
|
175
|
-
::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
|
176
|
-
end
|
177
|
-
RUBY
|
178
|
-
|
179
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
180
|
-
# def self.cached_exist_search_by_user_guid?(user_guid, options = {})
|
181
|
-
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
182
|
-
# end
|
183
|
-
def self.#{method_name}?(#{expanded_method_args}, options = {})
|
184
|
-
::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
|
185
|
-
end
|
186
|
-
RUBY
|
187
|
-
end
|
188
|
-
|
189
|
-
def _define_cached_find_method(method_name, *method_arguments)
|
190
|
-
method_arguments.flatten!
|
191
|
-
expanded_method_args = method_arguments.join(",")
|
192
|
-
sorted_method_args = method_arguments.sort.join(",")
|
193
|
-
|
194
|
-
expanded_search_args = ""
|
195
|
-
method_arguments.each do |method_argument|
|
196
|
-
expanded_search_args << ":#{method_argument} => #{method_argument},"
|
197
|
-
end
|
198
|
-
|
199
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
200
|
-
# def self.cached_find_by_user_guid(user_guid, options = {})
|
201
|
-
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
202
|
-
#
|
203
|
-
# ::ActiveRemote::Cached.cache.fetch([name, "#find", user_guid], options) do
|
204
|
-
# self.find(:user_guid => user_guid)
|
205
|
-
# end
|
206
|
-
# end
|
207
|
-
#
|
208
|
-
# If a block is given, it is incumbent on the caller to make sure the expectation
|
209
|
-
# of the result object is maintained for requests/responses
|
210
|
-
#
|
211
|
-
def self.#{method_name}(#{expanded_method_args}, options = {})
|
212
|
-
options = ::ActiveRemote::Cached.default_options.merge(options)
|
213
|
-
|
214
|
-
::ActiveRemote::Cached.cache.fetch([name, "#find", #{sorted_method_args}], options) do
|
215
|
-
if block_given?
|
216
|
-
yield
|
217
|
-
else
|
218
|
-
self.find(#{expanded_search_args})
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
RUBY
|
223
|
-
end
|
224
|
-
|
225
|
-
def _define_cached_search_method(method_name, *method_arguments)
|
226
|
-
method_arguments.flatten!
|
227
|
-
expanded_method_args = method_arguments.join(",")
|
228
|
-
sorted_method_args = method_arguments.sort.join(",")
|
229
|
-
|
230
|
-
expanded_search_args = ""
|
231
|
-
method_arguments.each do |method_argument|
|
232
|
-
expanded_search_args << ":#{method_argument} => #{method_argument},"
|
233
|
-
end
|
234
|
-
|
235
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
236
|
-
# def self.cached_search_by_user_guid(user_guid, options = {})
|
237
|
-
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
238
|
-
#
|
239
|
-
# ::ActiveRemote::Cached.cache.fetch([name, "#search", user_guid], options) do
|
240
|
-
# self.search(:user_guid => user_guid)
|
241
|
-
# end
|
242
|
-
# end
|
243
|
-
#
|
244
|
-
# If a block is given, it is incumbent on the caller to make sure the expectation
|
245
|
-
# of the result object is maintained for requests/responses
|
246
|
-
#
|
247
|
-
def self.#{method_name}(#{expanded_method_args}, options = {})
|
248
|
-
options = ::ActiveRemote::Cached.default_options.merge(options)
|
249
|
-
|
250
|
-
::ActiveRemote::Cached.cache.fetch([name, "#search", #{sorted_method_args}], options) do
|
251
|
-
if block_given?
|
252
|
-
yield
|
253
|
-
else
|
254
|
-
self.search(#{expanded_search_args})
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
RUBY
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
1
|
+
require "active_remote/cached"
|
@@ -0,0 +1,269 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_support/cache"
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/array/extract_options"
|
5
|
+
|
6
|
+
require "active_remote/cached/cache"
|
7
|
+
require "active_remote/cached/version"
|
8
|
+
|
9
|
+
require "active_remote/cached/railtie" if defined?(Rails)
|
10
|
+
|
11
|
+
module ActiveRemote
|
12
|
+
module Cached
|
13
|
+
extend ::ActiveSupport::Concern
|
14
|
+
|
15
|
+
def self.cache(cache_provider = nil)
|
16
|
+
if cache_provider
|
17
|
+
@cache_provider = ::ActiveRemote::Cached::Cache.new(cache_provider)
|
18
|
+
end
|
19
|
+
|
20
|
+
@cache_provider
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.default_options(options = nil)
|
24
|
+
if options
|
25
|
+
@default_options = options
|
26
|
+
end
|
27
|
+
|
28
|
+
@default_options || {}
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
def cached_finders_for(*cached_finder_keys)
|
33
|
+
options = cached_finder_keys.extract_options!
|
34
|
+
|
35
|
+
cached_finder_keys.each do |cached_finder_key|
|
36
|
+
_create_cached_finder_for(cached_finder_key, options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def cached_finders(*keys)
|
41
|
+
cached_finders_for(*keys)
|
42
|
+
end
|
43
|
+
|
44
|
+
def cached_find(argument_hash, options = {})
|
45
|
+
method_name = _cached_find_method_name(argument_hash.keys)
|
46
|
+
arguments = argument_hash.values
|
47
|
+
|
48
|
+
if block_given?
|
49
|
+
__send__(method_name, *arguments, options) do
|
50
|
+
yield
|
51
|
+
end
|
52
|
+
else
|
53
|
+
__send__(method_name, *arguments, options)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def cached_search(argument_hash, options = {})
|
58
|
+
method_name = _cached_search_method_name(argument_hash.keys)
|
59
|
+
arguments = argument_hash.values
|
60
|
+
|
61
|
+
if block_given?
|
62
|
+
__send__(method_name, *arguments, options) do
|
63
|
+
yield
|
64
|
+
end
|
65
|
+
else
|
66
|
+
__send__(method_name, *arguments, options)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Underscored Methods
|
72
|
+
#
|
73
|
+
def _create_cached_finder_for(cached_finder_key, options = {})
|
74
|
+
cached_finder_key_set = [ cached_finder_key ].flatten.sort
|
75
|
+
|
76
|
+
##
|
77
|
+
# Run each permutation of the arguments passed in
|
78
|
+
# and define each finder/searcher
|
79
|
+
#
|
80
|
+
cached_finder_key_set.permutation do |arguments|
|
81
|
+
delete_method_name = _cached_delete_method_name(arguments)
|
82
|
+
exist_find_method_name = _cached_exist_find_method_name(arguments)
|
83
|
+
exist_search_method_name = _cached_exist_search_method_name(arguments)
|
84
|
+
find_method_name = _cached_find_method_name(arguments)
|
85
|
+
search_method_name = _cached_search_method_name(arguments)
|
86
|
+
|
87
|
+
unless self.respond_to?(delete_method_name)
|
88
|
+
_define_cached_delete_method(delete_method_name, arguments)
|
89
|
+
end
|
90
|
+
|
91
|
+
unless self.respond_to?(exist_find_method_name)
|
92
|
+
_define_cached_exist_find_method(exist_find_method_name, arguments)
|
93
|
+
end
|
94
|
+
|
95
|
+
unless self.respond_to?(exist_search_method_name)
|
96
|
+
_define_cached_exist_search_method(exist_search_method_name, arguments)
|
97
|
+
end
|
98
|
+
|
99
|
+
unless self.respond_to?(find_method_name)
|
100
|
+
_define_cached_find_method(find_method_name, arguments)
|
101
|
+
end
|
102
|
+
|
103
|
+
unless self.respond_to?(search_method_name)
|
104
|
+
_define_cached_search_method(search_method_name, arguments)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def _cached_delete_method_name(arguments)
|
110
|
+
"cached_delete_by_#{arguments.join('_and_')}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def _cached_exist_find_method_name(arguments)
|
114
|
+
"cached_exist_find_by_#{arguments.join('_and_')}"
|
115
|
+
end
|
116
|
+
|
117
|
+
def _cached_exist_search_method_name(arguments)
|
118
|
+
"cached_exist_search_by_#{arguments.join('_and_')}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def _cached_find_method_name(arguments)
|
122
|
+
"cached_find_by_#{arguments.join('_and_')}"
|
123
|
+
end
|
124
|
+
|
125
|
+
def _cached_search_method_name(arguments)
|
126
|
+
"cached_search_by_#{arguments.join('_and_')}"
|
127
|
+
end
|
128
|
+
|
129
|
+
def _define_cached_delete_method(method_name, *method_arguments)
|
130
|
+
method_arguments.flatten!
|
131
|
+
expanded_method_args = method_arguments.join(",")
|
132
|
+
sorted_method_args = method_arguments.sort.join(",")
|
133
|
+
|
134
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
135
|
+
# def self.cached_delete_by_user_guid(user_guid, options = {})
|
136
|
+
# ::ActiveRemote::Cached.cache.delete([name, user_guid])
|
137
|
+
# end
|
138
|
+
def self.#{method_name}(#{expanded_method_args}, options = {})
|
139
|
+
::ActiveRemote::Cached.cache.delete([name, "#search", #{sorted_method_args}])
|
140
|
+
::ActiveRemote::Cached.cache.delete([name, "#find", #{sorted_method_args}])
|
141
|
+
end
|
142
|
+
RUBY
|
143
|
+
end
|
144
|
+
|
145
|
+
def _define_cached_exist_find_method(method_name, *method_arguments)
|
146
|
+
method_arguments.flatten!
|
147
|
+
expanded_method_args = method_arguments.join(",")
|
148
|
+
sorted_method_args = method_arguments.sort.join(",")
|
149
|
+
|
150
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
151
|
+
# def self.cached_exist_find_by_user_guid(user_guid, options = {})
|
152
|
+
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
153
|
+
# end
|
154
|
+
def self.#{method_name}(#{expanded_method_args}, options = {})
|
155
|
+
::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
|
156
|
+
end
|
157
|
+
RUBY
|
158
|
+
|
159
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
160
|
+
# def self.cached_exist_find_by_user_guid?(user_guid, options = {})
|
161
|
+
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
162
|
+
# end
|
163
|
+
def self.#{method_name}?(#{expanded_method_args}, options = {})
|
164
|
+
::ActiveRemote::Cached.cache.exist?([name, "#find", #{sorted_method_args}])
|
165
|
+
end
|
166
|
+
RUBY
|
167
|
+
end
|
168
|
+
|
169
|
+
def _define_cached_exist_search_method(method_name, *method_arguments)
|
170
|
+
method_arguments.flatten!
|
171
|
+
expanded_method_args = method_arguments.join(",")
|
172
|
+
sorted_method_args = method_arguments.sort.join(",")
|
173
|
+
|
174
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
175
|
+
# def self.cached_exist_search_by_user_guid(user_guid, options = {})
|
176
|
+
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
177
|
+
# end
|
178
|
+
def self.#{method_name}(#{expanded_method_args}, options = {})
|
179
|
+
::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
|
180
|
+
end
|
181
|
+
RUBY
|
182
|
+
|
183
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
184
|
+
# def self.cached_exist_search_by_user_guid?(user_guid, options = {})
|
185
|
+
# ::ActiveRemote::Cached.cache.exist?([name, user_guid])
|
186
|
+
# end
|
187
|
+
def self.#{method_name}?(#{expanded_method_args}, options = {})
|
188
|
+
::ActiveRemote::Cached.cache.exist?([name, "#search", #{sorted_method_args}])
|
189
|
+
end
|
190
|
+
RUBY
|
191
|
+
end
|
192
|
+
|
193
|
+
def _define_cached_find_method(method_name, *method_arguments)
|
194
|
+
method_arguments.flatten!
|
195
|
+
expanded_method_args = method_arguments.join(",")
|
196
|
+
sorted_method_args = method_arguments.sort.join(",")
|
197
|
+
|
198
|
+
expanded_search_args = ""
|
199
|
+
method_arguments.each do |method_argument|
|
200
|
+
expanded_search_args << ":#{method_argument} => #{method_argument},"
|
201
|
+
end
|
202
|
+
|
203
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
204
|
+
# def self.cached_find_by_user_guid(user_guid, options = {})
|
205
|
+
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
206
|
+
#
|
207
|
+
# ::ActiveRemote::Cached.cache.fetch([name, "#find", user_guid], options) do
|
208
|
+
# self.find(:user_guid => user_guid)
|
209
|
+
# end
|
210
|
+
# end
|
211
|
+
#
|
212
|
+
# If a block is given, it is incumbent on the caller to make sure the expectation
|
213
|
+
# of the result object is maintained for requests/responses
|
214
|
+
#
|
215
|
+
def self.#{method_name}(#{expanded_method_args}, options = {})
|
216
|
+
options = ::ActiveRemote::Cached.default_options.merge(options)
|
217
|
+
|
218
|
+
::ActiveRemote::Cached.cache.fetch([name, "#find", #{sorted_method_args}], options) do
|
219
|
+
if block_given?
|
220
|
+
yield
|
221
|
+
else
|
222
|
+
self.find(#{expanded_search_args})
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
RUBY
|
227
|
+
end
|
228
|
+
|
229
|
+
def _define_cached_search_method(method_name, *method_arguments)
|
230
|
+
method_arguments.flatten!
|
231
|
+
expanded_method_args = method_arguments.join(",")
|
232
|
+
sorted_method_args = method_arguments.sort.join(",")
|
233
|
+
|
234
|
+
expanded_search_args = ""
|
235
|
+
method_arguments.each do |method_argument|
|
236
|
+
expanded_search_args << ":#{method_argument} => #{method_argument},"
|
237
|
+
end
|
238
|
+
|
239
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
240
|
+
# def self.cached_search_by_user_guid(user_guid, options = {})
|
241
|
+
# options = ::ActiveRemote::Cached.default_options.merge(options)
|
242
|
+
#
|
243
|
+
# ::ActiveRemote::Cached.cache.fetch([name, "#search", user_guid], options) do
|
244
|
+
# self.search(:user_guid => user_guid)
|
245
|
+
# end
|
246
|
+
# end
|
247
|
+
#
|
248
|
+
# If a block is given, it is incumbent on the caller to make sure the expectation
|
249
|
+
# of the result object is maintained for requests/responses
|
250
|
+
#
|
251
|
+
def self.#{method_name}(#{expanded_method_args}, options = {})
|
252
|
+
options = ::ActiveRemote::Cached.default_options.merge(options)
|
253
|
+
|
254
|
+
::ActiveRemote::Cached.cache.fetch([name, "#search", #{sorted_method_args}], options) do
|
255
|
+
if block_given?
|
256
|
+
yield
|
257
|
+
else
|
258
|
+
self.search(#{expanded_search_args})
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
RUBY
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
# Initialize the cache provider with a MemoryStore cache
|
267
|
+
cache(ActiveSupport::Cache::MemoryStore.new)
|
268
|
+
end
|
269
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActiveRemote
|
2
|
+
module Cached
|
3
|
+
class Railtie < Rails::Railtie
|
4
|
+
initializer "active_remote-cached.initialize_cache" do |app|
|
5
|
+
ActiveRemote::Cached.cache(app.cache)
|
6
|
+
ActiveRemote::Cached.default_options(:race_condition_ttl => 5.seconds)
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveSupport.on_load(:active_remote) do
|
10
|
+
include ActiveRemote::Cached
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_remote-cached
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_remote
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mocha
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: ' Provides "cached" finders and a DSL to enumerate which finders should
|
@@ -102,20 +102,22 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
-
- .gitignore
|
105
|
+
- ".gitignore"
|
106
106
|
- Gemfile
|
107
107
|
- LICENSE.txt
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
110
|
- active_remote-cached.gemspec
|
111
111
|
- lib/active_remote-cached.rb
|
112
|
-
- lib/active_remote
|
113
|
-
- lib/active_remote
|
114
|
-
-
|
115
|
-
-
|
116
|
-
- spec/
|
117
|
-
- spec/
|
118
|
-
- spec/
|
112
|
+
- lib/active_remote/cached.rb
|
113
|
+
- lib/active_remote/cached/cache.rb
|
114
|
+
- lib/active_remote/cached/railtie.rb
|
115
|
+
- lib/active_remote/cached/version.rb
|
116
|
+
- spec/active_remote/cached/cache_spec.rb
|
117
|
+
- spec/active_remote/cached_delete_methods_spec.rb
|
118
|
+
- spec/active_remote/cached_exist_methods_spec.rb
|
119
|
+
- spec/active_remote/cached_find_methods_spec.rb
|
120
|
+
- spec/active_remote/cached_search_methods_spec.rb
|
119
121
|
- spec/spec_helper.rb
|
120
122
|
homepage: ''
|
121
123
|
licenses: []
|
@@ -126,12 +128,12 @@ require_paths:
|
|
126
128
|
- lib
|
127
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
130
|
requirements:
|
129
|
-
- -
|
131
|
+
- - ">="
|
130
132
|
- !ruby/object:Gem::Version
|
131
133
|
version: '0'
|
132
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
135
|
requirements:
|
134
|
-
- -
|
136
|
+
- - ">="
|
135
137
|
- !ruby/object:Gem::Version
|
136
138
|
version: '0'
|
137
139
|
requirements: []
|
@@ -142,9 +144,9 @@ specification_version: 4
|
|
142
144
|
summary: Provides a configuration for caching mechanisms and finders on ActiveRemote
|
143
145
|
models that are cached/cacheable
|
144
146
|
test_files:
|
145
|
-
- spec/cache_spec.rb
|
146
|
-
- spec/cached_delete_methods_spec.rb
|
147
|
-
- spec/cached_exist_methods_spec.rb
|
148
|
-
- spec/cached_find_methods_spec.rb
|
149
|
-
- spec/cached_search_methods_spec.rb
|
147
|
+
- spec/active_remote/cached/cache_spec.rb
|
148
|
+
- spec/active_remote/cached_delete_methods_spec.rb
|
149
|
+
- spec/active_remote/cached_exist_methods_spec.rb
|
150
|
+
- spec/active_remote/cached_find_methods_spec.rb
|
151
|
+
- spec/active_remote/cached_search_methods_spec.rb
|
150
152
|
- spec/spec_helper.rb
|