multi_fetch_fragments 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/multi_fetch_fragments.rb +10 -12
- metadata +51 -24
@@ -18,17 +18,19 @@ module MultiFetchFragments
|
|
18
18
|
|
19
19
|
if ActionController::Base.perform_caching && @options[:cache].present?
|
20
20
|
|
21
|
+
additional_cache_options = @options.fetch(:cache_options, {})
|
21
22
|
keys_to_collection_map = {}
|
22
23
|
|
23
|
-
@collection.each do |item|
|
24
|
+
@collection.each do |item|
|
24
25
|
key = @options[:cache].is_a?(Proc) ? @options[:cache].call(item) : item
|
25
26
|
expanded_key = ActiveSupport::Cache.expand_cache_key(key)
|
26
|
-
keys_to_collection_map[expanded_key] = item
|
27
|
+
keys_to_collection_map[expanded_key] = item
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
+
# cache.read_multi & cache.write interfaces may require mutable keys, ie. dalli 2.6.0
|
31
|
+
mutable_keys = keys_to_collection_map.keys.collect { |key| key.dup }
|
30
32
|
|
31
|
-
result_hash = Rails.cache.read_multi(
|
33
|
+
result_hash = Rails.cache.read_multi(mutable_keys)
|
32
34
|
|
33
35
|
# if we had a cached value, we don't need to render that object from the collection.
|
34
36
|
# if it wasn't cached, we need to render those objects as before
|
@@ -43,22 +45,18 @@ module MultiFetchFragments
|
|
43
45
|
|
44
46
|
# sequentially render any non-cached objects remaining
|
45
47
|
if @collection.any?
|
46
|
-
|
47
|
-
#store these to use later for sorting the results
|
48
|
-
collection_objects_clone = @collection.clone
|
49
|
-
|
50
48
|
non_cached_results = @template ? collection_with_template : collection_without_template
|
51
49
|
end
|
52
50
|
|
53
51
|
# sort the result according to the keys that were fed in, cache the non-cached results
|
54
|
-
|
52
|
+
mutable_keys.each do |key|
|
55
53
|
|
56
54
|
cached_value = result_hash[key]
|
57
55
|
if cached_value
|
58
56
|
results << cached_value
|
59
57
|
else
|
60
58
|
non_cached_result = non_cached_results.shift
|
61
|
-
Rails.cache.write(key, non_cached_result)
|
59
|
+
Rails.cache.write(key, non_cached_result, additional_cache_options)
|
62
60
|
|
63
61
|
results << non_cached_result
|
64
62
|
end
|
@@ -67,7 +65,7 @@ module MultiFetchFragments
|
|
67
65
|
else
|
68
66
|
results = @template ? collection_with_template : collection_without_template
|
69
67
|
end
|
70
|
-
|
68
|
+
|
71
69
|
results.join(spacer).html_safe
|
72
70
|
end
|
73
71
|
|
@@ -78,4 +76,4 @@ module MultiFetchFragments
|
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
81
|
-
end
|
79
|
+
end
|
metadata
CHANGED
@@ -1,46 +1,73 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_fetch_fragments
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 10
|
9
|
+
version: 0.0.10
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Nathan Kontny
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
16
|
+
|
17
|
+
date: 2012-12-17 00:00:00 -06:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec-rails
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
version: "2"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
14
32
|
description:
|
15
33
|
email: nate.kontny@gmail.com
|
16
34
|
executables: []
|
35
|
+
|
17
36
|
extensions: []
|
37
|
+
|
18
38
|
extra_rdoc_files: []
|
19
|
-
|
39
|
+
|
40
|
+
files:
|
20
41
|
- lib/multi_fetch_fragments.rb
|
42
|
+
has_rdoc: true
|
21
43
|
homepage:
|
22
44
|
licenses: []
|
45
|
+
|
23
46
|
post_install_message:
|
24
47
|
rdoc_options: []
|
25
|
-
|
48
|
+
|
49
|
+
require_paths:
|
26
50
|
- lib
|
27
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
requirements:
|
36
|
-
- -
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
39
65
|
requirements: []
|
66
|
+
|
40
67
|
rubyforge_project:
|
41
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.3.6
|
42
69
|
signing_key:
|
43
70
|
specification_version: 3
|
44
|
-
summary: multi_fetch_fragments allows you to render a collection of partials through
|
45
|
-
Rails multi read caching mechanism.
|
71
|
+
summary: multi_fetch_fragments allows you to render a collection of partials through Rails multi read caching mechanism.
|
46
72
|
test_files: []
|
73
|
+
|