lib/cached_resource/caching.rb in cached_resource-5.2.0 vs lib/cached_resource/caching.rb in cached_resource-5.3.0

- old
+ new

@@ -15,10 +15,11 @@ # Find a resource using the cache or resend the request # if :reload is set to true or caching is disabled. def find_with_cache(*arguments) arguments << {} unless arguments.last.is_a?(Hash) should_reload = arguments.last.delete(:reload) || !cached_resource.enabled + should_reload = true if !cached_resource.cache_collections && is_any_collection?(*arguments) arguments.pop if arguments.last.empty? key = cache_key(arguments) should_reload ? find_via_reload(key, *arguments) : find_via_cache(key, *arguments) end @@ -39,10 +40,11 @@ # Re/send the request to fetch the resource. Cache the response # for the request. def find_via_reload(key, *arguments) object = find_without_cache(*arguments) cache_collection_synchronize(object, *arguments) if cached_resource.collection_synchronize + return object if !cached_resource.cache_collections && is_any_collection?(*arguments) cache_write(key, object) cache_read(key) end # If this is a pure, unadulterated "all" request @@ -78,9 +80,15 @@ # Determine if the given arguments represent # the entire collection of objects. def is_collection?(*arguments) arguments == cached_resource.collection_arguments + end + + # Determine if the given arguments represent + # any collection of objects + def is_any_collection?(*arguments) + cached_resource.collection_arguments.all?{ |arg| arguments.include?(arg) } || arguments.include?(:all) end # Read a entry from the cache for the given key. def cache_read(key) object = cached_resource.cache.read(key).try do |json_cache|