laserlemon-cache_flow 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/cache_flow.gemspec +1 -1
- data/lib/cache_flow.rb +29 -13
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/cache_flow.gemspec
CHANGED
data/lib/cache_flow.rb
CHANGED
@@ -30,27 +30,43 @@ module LaserLemon
|
|
30
30
|
end
|
31
31
|
|
32
32
|
module InstanceMethods
|
33
|
-
def to_xml_with_cache_flow(options = {})
|
34
|
-
|
35
|
-
|
33
|
+
def to_xml_with_cache_flow(options = {}, &block)
|
34
|
+
if cache_xml?(options, &block)
|
35
|
+
key = xml_cache_key(options.merge!(:cache => false))
|
36
|
+
value = to_xml_without_cache_flow(options, &block)
|
37
|
+
Rails.cache.fetch(key){ value.respond_to?(:dup) ? value.dup : value }
|
38
|
+
else
|
39
|
+
to_xml_without_cache_flow(options, &block)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
|
-
def to_json_with_cache_flow(options = {})
|
40
|
-
|
41
|
-
|
43
|
+
def to_json_with_cache_flow(options = {}, &block)
|
44
|
+
if cache_json?(options)
|
45
|
+
key = json_cache_key(options.merge!(:cache => false))
|
46
|
+
value = to_json_without_cache_flow(options, &block)
|
47
|
+
Rails.cache.fetch(key){ value.respond_to?(:dup) ? value.dup : value }
|
48
|
+
else
|
49
|
+
to_json_without_cache_flow(options, &block)
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
45
53
|
private
|
46
54
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
55
|
+
def cache_xml?(options, &block)
|
56
|
+
case
|
57
|
+
when block_given?, options.has_key?(:procs) then false
|
58
|
+
else cache_serialization?(options)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def cache_json?(options)
|
63
|
+
cache_serialization?(options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def cache_serialization?(options)
|
67
|
+
case
|
68
|
+
when options.has_key?(:cache) then options.delete(:cache)
|
69
|
+
else self.class.cache_serialization
|
54
70
|
end
|
55
71
|
end
|
56
72
|
|