active_remote-cached 1.0.0 → 1.2.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.
@@ -1,33 +1,38 @@
1
- require "active_support"
2
- require "active_support/cache"
3
- require "active_support/concern"
4
- require "active_support/core_ext/array/extract_options"
1
+ # frozen_string_literal: true
5
2
 
6
- require "active_remote/cached/argument_keys"
7
- require "active_remote/cached/cache"
8
- require "active_remote/cached/version"
9
- require "active_remote/errors"
3
+ require 'active_support'
4
+ require 'active_support/cache'
5
+ require 'active_support/concern'
6
+ require 'active_support/core_ext/array/extract_options'
7
+
8
+ require 'active_remote/cached/argument_keys'
9
+ require 'active_remote/cached/cache'
10
+ require 'active_remote/cached/version'
11
+ require 'active_remote/errors'
10
12
 
11
13
  module ActiveRemote
12
14
  module Cached
13
15
  extend ::ActiveSupport::Concern
14
16
 
15
- # When upgrading Rails versions, don't reuse the same cache key, because you can't rely upon the serialized objects to be consistent across versions.
16
- # To fix, this adds a cache key that caches the ruby engine version and the activesupport version to prevent cache re-use across different versions.
17
+ # When upgrading Rails versions, don't reuse the same cache key,
18
+ # because you can't rely upon the serialized objects to be consistent across versions.
19
+ # To fix, this adds a cache key that caches the ruby engine version
20
+ # and the activesupport version to prevent cache re-use across different versions.
17
21
  RUBY_AND_ACTIVE_SUPPORT_VERSION = "#{RUBY_ENGINE_VERSION}:#{ActiveSupport::VERSION::STRING}".freeze
18
22
 
19
23
  def self.cache(cache_provider = nil)
20
24
  if cache_provider
25
+ nested_caching = @cache_provider&.nested_caching?
21
26
  @cache_provider = ::ActiveRemote::Cached::Cache.new(cache_provider)
27
+ # A new Cache starts with nested caching off, so carry the setting over.
28
+ @cache_provider.enable_nested_caching! if nested_caching
22
29
  end
23
30
 
24
31
  @cache_provider
25
32
  end
26
33
 
27
34
  def self.default_options(options = nil)
28
- if options
29
- @default_options = options
30
- end
35
+ @default_options = options if options
31
36
 
32
37
  @default_options || {}
33
38
  end
@@ -38,6 +43,29 @@ module ActiveRemote
38
43
  @cached_methods
39
44
  end
40
45
 
46
+ # The options each cached finder was declared with, keyed by method name.
47
+ # The generated methods read this at call time. Interpolating the options
48
+ # into the generated source instead would require every value to have a
49
+ # literal form, and a value such as 5.minutes does not.
50
+ def cached_finder_options
51
+ @cached_finder_options ||= {}
52
+ end
53
+
54
+ # A subclass inherits the finder methods its parent defined, but not the
55
+ # parent registry, so the lookup walks up the superclass chain.
56
+ def _cached_finder_options_for(method_name)
57
+ klass = self
58
+
59
+ while klass.respond_to?(:cached_finder_options)
60
+ options = klass.cached_finder_options[method_name]
61
+ return options if options
62
+
63
+ klass = klass.superclass
64
+ end
65
+
66
+ {}
67
+ end
68
+
41
69
  def cached_finders_for(*cached_finder_keys)
42
70
  options = cached_finder_keys.extract_options!
43
71
 
@@ -50,27 +78,23 @@ module ActiveRemote
50
78
  cached_finders_for(*keys)
51
79
  end
52
80
 
53
- def cached_find(argument_hash, options = {})
81
+ def cached_find(argument_hash, options = {}, &block)
54
82
  method_name = _cached_find_method_name(argument_hash.keys)
55
83
  arguments = argument_hash.keys.sort.map { |k| argument_hash[k] }
56
84
 
57
85
  if block_given?
58
- __send__(method_name, *arguments, options) do
59
- yield
60
- end
86
+ __send__(method_name, *arguments, options, &block)
61
87
  else
62
88
  __send__(method_name, *arguments, options)
63
89
  end
64
90
  end
65
91
 
66
- def cached_search(argument_hash, options = {})
92
+ def cached_search(argument_hash, options = {}, &block)
67
93
  method_name = _cached_search_method_name(argument_hash.keys)
68
94
  arguments = argument_hash.keys.sort.map { |k| argument_hash[k] }
69
95
 
70
96
  if block_given?
71
- __send__(method_name, *arguments, options) do
72
- yield
73
- end
97
+ __send__(method_name, *arguments, options, &block)
74
98
  else
75
99
  __send__(method_name, *arguments, options)
76
100
  end
@@ -101,48 +125,50 @@ module ActiveRemote
101
125
  # Underscored Methods
102
126
  #
103
127
  def _method_missing_name(m)
104
- regex = /(cached_(?:delete|exist_search|search|exist_find|find)_by_)([a-zA-Z_]*)(!|\?)?/
128
+ regex = /(cached_(?:delete|exist_search|search|exist_find|find)_by_)([0-9a-zA-Z_]*)(!|\?)?/
105
129
 
106
- if m.to_s =~ regex
107
- params = $2.split("_and_")
108
- "#{$1}#{params.sort.join("_and_")}#{$3}".to_sym
109
- else
110
- nil
111
- end
130
+ return unless m.to_s =~ regex
131
+
132
+ params = ::Regexp.last_match(2).split('_and_')
133
+ "#{::Regexp.last_match(1)}#{params.sort.join('_and_')}#{::Regexp.last_match(3)}".to_sym
112
134
  end
113
135
 
114
136
  def _args_in_sorted_order(m, args)
115
- regex = /cached_(?:delete|exist_search|search|exist_find|find)_by_([a-zA-Z_]*)(!|\?)?/
137
+ regex = /cached_(?:delete|exist_search|search|exist_find|find)_by_([0-9a-zA-Z_]*)(!|\?)?/
116
138
 
117
- method_name = _method_missing_name(m)
139
+ called_match = m.match(regex)
140
+ sorted_match = _method_missing_name(m).match(regex)
118
141
 
119
- match_1 = m.match(regex)
120
- match_2 = method_name.match(regex)
142
+ return args unless called_match[1] && sorted_match[1]
121
143
 
122
- args_in_order = []
144
+ called_field_names = called_match[1].split('_and_')
145
+ sorted_field_names = sorted_match[1].split('_and_')
123
146
 
124
- if match_1[1] && match_2[1]
125
- orignal_args_name = match_1[1].split("_and_")
126
- args_names_in_order = match_2[1].split("_and_")
147
+ _reorder_args(m, args, called_field_names, sorted_field_names)
148
+ end
127
149
 
128
- args_names_in_order.each do |arg_name|
129
- index = orignal_args_name.index(arg_name)
130
- args_in_order << args[index]
131
- end
150
+ def _reorder_args(m, args, called_field_names, sorted_field_names)
151
+ if args.size < called_field_names.size
152
+ raise ::ArgumentError,
153
+ "wrong number of arguments to #{m} (given #{args.size}, expected #{called_field_names.size})"
154
+ end
132
155
 
133
- if args.size > args_in_order.size
134
- # Add options if passed
135
- args_in_order << args.last
136
- end
156
+ args_in_order = sorted_field_names.map do |field_name|
157
+ index = called_field_names.index(field_name)
158
+ raise ::ArgumentError, "#{m} has no argument named #{field_name}" if index.nil?
137
159
 
138
- args_in_order
139
- else
140
- args
160
+ args[index]
141
161
  end
162
+
163
+ # Add the options hash if the caller passed one.
164
+ args_in_order << args.last if args.size > called_field_names.size
165
+
166
+ args_in_order
142
167
  end
143
168
 
169
+ # rubocop:disable Metrics/AbcSize
144
170
  def _create_cached_finder_for(cached_finder_key, options = {})
145
- cached_finder_key_set = [ cached_finder_key ].flatten.sort
171
+ cached_finder_key_set = [cached_finder_key].flatten.sort
146
172
 
147
173
  delete_method_name = _cached_delete_method_name(cached_finder_key_set)
148
174
  exist_find_method_name = _cached_exist_find_method_name(cached_finder_key_set)
@@ -154,7 +180,7 @@ module ActiveRemote
154
180
  unless cached_methods.include?(delete_method_name)
155
181
  _define_cached_delete_method(delete_method_name, cached_finder_key_set, options)
156
182
  end
157
-
183
+
158
184
  unless cached_methods.include?(exist_find_method_name)
159
185
  _define_cached_exist_find_method(exist_find_method_name, cached_finder_key_set, options)
160
186
  end
@@ -171,10 +197,11 @@ module ActiveRemote
171
197
  _define_cached_search_bang_method(search_bang_method_name, cached_finder_key_set, options)
172
198
  end
173
199
 
174
- unless cached_methods.include?(search_method_name)
175
- _define_cached_search_method(search_method_name, cached_finder_key_set, options)
176
- end
200
+ return if cached_methods.include?(search_method_name)
201
+
202
+ _define_cached_search_method(search_method_name, cached_finder_key_set, options)
177
203
  end
204
+ # rubocop:enable Metrics/AbcSize
178
205
 
179
206
  def _cached_delete_method_name(arguments)
180
207
  "cached_delete_by_#{arguments.sort.join('_and_')}"
@@ -196,25 +223,41 @@ module ActiveRemote
196
223
  "cached_search_by_#{arguments.sort.join('_and_')}"
197
224
  end
198
225
 
199
- def _define_cached_delete_method(method_name, *method_arguments, cached_finder_options)
226
+ def _expanded_search_args(method_arguments)
227
+ method_arguments.map { |method_argument| ":#{method_argument} => #{method_argument}," }.join
228
+ end
229
+
230
+ # Returns the source text that builds the cache key for a generated
231
+ # method. The key names each field, so that two finders that take the
232
+ # same values do not share one cache entry.
233
+ def _expanded_cache_key_args(method_arguments)
234
+ sorted_arguments = method_arguments.sort
235
+ field_names = sorted_arguments.map { |argument| ":#{argument}" }.join(',')
236
+
237
+ '::ActiveRemote::Cached::ArgumentKeys.for_fields(' \
238
+ "[#{field_names}], [#{sorted_arguments.join(',')}], __active_remote_cached_options" \
239
+ ').cache_key'
240
+ end
241
+
242
+ def _define_cached_delete_method(method_name, *method_arguments, cached_finder_options_hash)
200
243
  method_arguments.flatten!
201
- expanded_method_args = method_arguments.join(",")
202
- sorted_method_args = method_arguments.sort.join(",")
203
- cached_methods << method_name
244
+ expanded_method_args = method_arguments.join(',')
245
+ expanded_cache_key_args = _expanded_cache_key_args(method_arguments)
204
246
 
205
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
247
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
206
248
  # def self.cached_delete_by_user_guid(user_guid, options = {})
207
249
  # ::ActiveRemote::Cached.cache.delete([name, user_guid])
208
250
  # end
209
251
  def self.#{method_name}(#{expanded_method_args}, __active_remote_cached_options = {})
210
- __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(__active_remote_cached_options)
252
+ __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(_cached_finder_options_for('#{method_name}')).merge(__active_remote_cached_options)
211
253
  namespace = __active_remote_cached_options.delete(:namespace)
254
+ argument_cache_key = #{expanded_cache_key_args}
212
255
  find_cache_key = [
213
256
  RUBY_AND_ACTIVE_SUPPORT_VERSION,
214
257
  namespace,
215
258
  name,
216
259
  "#find",
217
- ::ActiveRemote::Cached::ArgumentKeys.new(#{sorted_method_args}, __active_remote_cached_options).cache_key
260
+ argument_cache_key
218
261
  ].compact
219
262
 
220
263
  search_cache_key = [
@@ -222,35 +265,36 @@ module ActiveRemote
222
265
  namespace,
223
266
  name,
224
267
  "#search",
225
- ::ActiveRemote::Cached::ArgumentKeys.new(#{sorted_method_args}, __active_remote_cached_options).cache_key
268
+ argument_cache_key
226
269
  ].compact
227
270
 
228
271
  ::ActiveRemote::Cached.cache.delete(find_cache_key)
229
272
  ::ActiveRemote::Cached.cache.delete(search_cache_key)
230
273
  end
231
274
  RUBY
275
+
276
+ cached_finder_options[method_name] = cached_finder_options_hash
277
+ cached_methods << method_name
232
278
  end
233
279
 
234
- def _define_cached_exist_find_method(method_name, *method_arguments, cached_finder_options)
280
+ def _define_cached_exist_find_method(method_name, *method_arguments, cached_finder_options_hash)
235
281
  method_arguments.flatten!
236
- expanded_method_args = method_arguments.join(",")
237
- sorted_method_args = method_arguments.sort.join(",")
238
- cached_methods << method_name
239
- cached_methods << "#{method_name}?"
282
+ expanded_method_args = method_arguments.join(',')
283
+ expanded_cache_key_args = _expanded_cache_key_args(method_arguments)
240
284
 
241
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
285
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
242
286
  # def self.cached_exist_find_by_user_guid(user_guid, options = {})
243
287
  # ::ActiveRemote::Cached.cache.exist?([name, user_guid])
244
288
  # end
245
289
  def self.#{method_name}(#{expanded_method_args}, __active_remote_cached_options = {})
246
- __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(__active_remote_cached_options)
290
+ __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(_cached_finder_options_for('#{method_name}')).merge(__active_remote_cached_options)
247
291
  namespace = __active_remote_cached_options.delete(:namespace)
248
292
  cache_key = [
249
293
  RUBY_AND_ACTIVE_SUPPORT_VERSION,
250
294
  namespace,
251
295
  name,
252
296
  "#find",
253
- ::ActiveRemote::Cached::ArgumentKeys.new(#{sorted_method_args}, __active_remote_cached_options).cache_key
297
+ #{expanded_cache_key_args}
254
298
  ].compact
255
299
 
256
300
  ::ActiveRemote::Cached.cache.exist?(cache_key)
@@ -258,28 +302,30 @@ module ActiveRemote
258
302
  RUBY
259
303
 
260
304
  singleton_class.send(:alias_method, "#{method_name}?", method_name)
261
- end
262
305
 
263
- def _define_cached_exist_search_method(method_name, *method_arguments, cached_finder_options)
264
- method_arguments.flatten!
265
- expanded_method_args = method_arguments.join(",")
266
- sorted_method_args = method_arguments.sort.join(",")
306
+ cached_finder_options[method_name] = cached_finder_options_hash
267
307
  cached_methods << method_name
268
308
  cached_methods << "#{method_name}?"
309
+ end
269
310
 
270
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
311
+ def _define_cached_exist_search_method(method_name, *method_arguments, cached_finder_options_hash)
312
+ method_arguments.flatten!
313
+ expanded_method_args = method_arguments.join(',')
314
+ expanded_cache_key_args = _expanded_cache_key_args(method_arguments)
315
+
316
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
271
317
  # def self.cached_exist_search_by_user_guid(user_guid, options = {})
272
318
  # ::ActiveRemote::Cached.cache.exist?([namespace, name, "#search", user_guid])
273
319
  # end
274
320
  def self.#{method_name}(#{expanded_method_args}, __active_remote_cached_options = {})
275
- __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(__active_remote_cached_options)
321
+ __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(_cached_finder_options_for('#{method_name}')).merge(__active_remote_cached_options)
276
322
  namespace = __active_remote_cached_options.delete(:namespace)
277
323
  cache_key = [
278
324
  RUBY_AND_ACTIVE_SUPPORT_VERSION,
279
325
  namespace,
280
326
  name,
281
327
  "#search",
282
- ::ActiveRemote::Cached::ArgumentKeys.new(#{sorted_method_args}, __active_remote_cached_options).cache_key
328
+ #{expanded_cache_key_args}
283
329
  ].compact
284
330
 
285
331
  ::ActiveRemote::Cached.cache.exist?(cache_key)
@@ -287,20 +333,20 @@ module ActiveRemote
287
333
  RUBY
288
334
 
289
335
  singleton_class.send(:alias_method, "#{method_name}?", method_name)
336
+
337
+ cached_finder_options[method_name] = cached_finder_options_hash
338
+ cached_methods << method_name
339
+ cached_methods << "#{method_name}?"
290
340
  end
291
341
 
292
- def _define_cached_find_method(method_name, *method_arguments, cached_finder_options)
342
+ def _define_cached_find_method(method_name, *method_arguments, cached_finder_options_hash)
293
343
  method_arguments.flatten!
294
- expanded_method_args = method_arguments.join(",")
295
- sorted_method_args = method_arguments.sort.join(",")
296
- cached_methods << method_name
344
+ expanded_method_args = method_arguments.join(',')
345
+ expanded_cache_key_args = _expanded_cache_key_args(method_arguments)
297
346
 
298
- expanded_search_args = ""
299
- method_arguments.each do |method_argument|
300
- expanded_search_args << ":#{method_argument} => #{method_argument},"
301
- end
347
+ expanded_search_args = _expanded_search_args(method_arguments)
302
348
 
303
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
349
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
304
350
  # def self.cached_find_by_user_guid(user_guid, options = {})
305
351
  # options = ::ActiveRemote::Cached.default_options.merge({}).merge(options)
306
352
  #
@@ -313,14 +359,14 @@ module ActiveRemote
313
359
  # of the result object is maintained for requests/responses
314
360
  #
315
361
  def self.#{method_name}(#{expanded_method_args}, __active_remote_cached_options = {})
316
- __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(__active_remote_cached_options)
362
+ __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(_cached_finder_options_for('#{method_name}')).merge(__active_remote_cached_options)
317
363
  namespace = __active_remote_cached_options.delete(:namespace)
318
364
  cache_key = [
319
365
  RUBY_AND_ACTIVE_SUPPORT_VERSION,
320
366
  namespace,
321
367
  name,
322
368
  "#find",
323
- ::ActiveRemote::Cached::ArgumentKeys.new(#{sorted_method_args}, __active_remote_cached_options).cache_key
369
+ #{expanded_cache_key_args}
324
370
  ].compact
325
371
 
326
372
  ::ActiveRemote::Cached.cache.fetch(cache_key, __active_remote_cached_options) do
@@ -332,20 +378,19 @@ module ActiveRemote
332
378
  end
333
379
  end
334
380
  RUBY
381
+
382
+ cached_finder_options[method_name] = cached_finder_options_hash
383
+ cached_methods << method_name
335
384
  end
336
385
 
337
- def _define_cached_search_method(method_name, *method_arguments, cached_finder_options)
386
+ def _define_cached_search_method(method_name, *method_arguments, cached_finder_options_hash)
338
387
  method_arguments.flatten!
339
- expanded_method_args = method_arguments.join(",")
340
- sorted_method_args = method_arguments.sort.join(",")
341
- cached_methods << method_name
388
+ expanded_method_args = method_arguments.join(',')
389
+ expanded_cache_key_args = _expanded_cache_key_args(method_arguments)
342
390
 
343
- expanded_search_args = ""
344
- method_arguments.each do |method_argument|
345
- expanded_search_args << ":#{method_argument} => #{method_argument},"
346
- end
391
+ expanded_search_args = _expanded_search_args(method_arguments)
347
392
 
348
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
393
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
349
394
  # def self.cached_search_by_user_guid(user_guid, options = {})
350
395
  # options = ::ActiveRemote::Cached.default_options.merge({}).merge(options)
351
396
  #
@@ -362,14 +407,14 @@ module ActiveRemote
362
407
  # of the result object is maintained for requests/responses
363
408
  #
364
409
  def self.#{method_name}(#{expanded_method_args}, __active_remote_cached_options = {})
365
- __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(__active_remote_cached_options)
410
+ __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(_cached_finder_options_for('#{method_name}')).merge(__active_remote_cached_options)
366
411
  namespace = __active_remote_cached_options.delete(:namespace)
367
412
  cache_key = [
368
413
  RUBY_AND_ACTIVE_SUPPORT_VERSION,
369
414
  namespace,
370
415
  name,
371
416
  "#search",
372
- ::ActiveRemote::Cached::ArgumentKeys.new(#{sorted_method_args}, __active_remote_cached_options).cache_key
417
+ #{expanded_cache_key_args}
373
418
  ].compact
374
419
 
375
420
  ::ActiveRemote::Cached.cache.fetch(cache_key, __active_remote_cached_options) do
@@ -381,20 +426,19 @@ module ActiveRemote
381
426
  end
382
427
  end
383
428
  RUBY
429
+
430
+ cached_finder_options[method_name] = cached_finder_options_hash
431
+ cached_methods << method_name
384
432
  end
385
433
 
386
- def _define_cached_search_bang_method(method_name, *method_arguments, cached_finder_options)
434
+ def _define_cached_search_bang_method(method_name, *method_arguments, cached_finder_options_hash)
387
435
  method_arguments.flatten!
388
- expanded_method_args = method_arguments.join(",")
389
- sorted_method_args = method_arguments.sort.join(",")
390
- cached_methods << method_name
436
+ expanded_method_args = method_arguments.join(',')
437
+ expanded_cache_key_args = _expanded_cache_key_args(method_arguments)
391
438
 
392
- expanded_search_args = ""
393
- method_arguments.each do |method_argument|
394
- expanded_search_args << ":#{method_argument} => #{method_argument},"
395
- end
439
+ expanded_search_args = _expanded_search_args(method_arguments)
396
440
 
397
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
441
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
398
442
  # def self.cached_search_by_user_guid!(user_guid, options = {})
399
443
  # options = ::ActiveRemote::Cached.default_options.merge({}).merge(options)
400
444
  #
@@ -407,7 +451,7 @@ module ActiveRemote
407
451
  # results = self.search(:user_guid => user_guid)
408
452
  # end
409
453
  #
410
- # raise ::ActiveRemote::RemoteRecordNotFound.new(self.class) if results.size <= 0
454
+ # raise ::ActiveRemote::RemoteRecordNotFound, self if results.nil? || results.first.nil?
411
455
  # results
412
456
  # end
413
457
  # end
@@ -416,14 +460,14 @@ module ActiveRemote
416
460
  # of the result object is maintained for requests/responses
417
461
  #
418
462
  def self.#{method_name}(#{expanded_method_args}, __active_remote_cached_options = {})
419
- __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(#{cached_finder_options}).merge(__active_remote_cached_options)
463
+ __active_remote_cached_options = ::ActiveRemote::Cached.default_options.merge(_cached_finder_options_for('#{method_name}')).merge(__active_remote_cached_options)
420
464
  namespace = __active_remote_cached_options.delete(:namespace)
421
465
  cache_key = [
422
466
  RUBY_AND_ACTIVE_SUPPORT_VERSION,
423
467
  namespace,
424
468
  name,
425
469
  "#search",
426
- ::ActiveRemote::Cached::ArgumentKeys.new(#{sorted_method_args}, __active_remote_cached_options).cache_key
470
+ #{expanded_cache_key_args}
427
471
  ].compact
428
472
 
429
473
  ::ActiveRemote::Cached.cache.fetch(cache_key, __active_remote_cached_options) do
@@ -435,11 +479,14 @@ module ActiveRemote
435
479
  results = self.search(#{expanded_search_args})
436
480
  end
437
481
 
438
- raise ::ActiveRemote::RemoteRecordNotFound.new(self.class) if results.first.nil?
482
+ raise ::ActiveRemote::RemoteRecordNotFound, self if results.nil? || results.first.nil?
439
483
  results
440
484
  end
441
485
  end
442
486
  RUBY
487
+
488
+ cached_finder_options[method_name] = cached_finder_options_hash
489
+ cached_methods << method_name
443
490
  end
444
491
  end
445
492
 
@@ -448,4 +495,4 @@ module ActiveRemote
448
495
  end
449
496
  end
450
497
 
451
- require "active_remote/cached/railtie" if defined?(Rails)
498
+ require 'active_remote/cached/railtie' if defined?(Rails)
@@ -1 +1,3 @@
1
- require "active_remote/cached"
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_remote/cached'