laserlemon-cache_flow 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/cache_flow.gemspec +2 -2
- data/lib/cache_flow.rb +22 -13
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/cache_flow.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cache_flow}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["laserlemon"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-30}
|
13
13
|
s.description = %q{Easily cache ActiveRecord's to_xml and to_json outputs}
|
14
14
|
s.email = %q{steve@laserlemon.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/cache_flow.rb
CHANGED
@@ -32,26 +32,35 @@ module LaserLemon
|
|
32
32
|
module InstanceMethods
|
33
33
|
def to_xml_with_cache_flow(options = {}, &block)
|
34
34
|
if cache_xml?(options, &block)
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
serializer = ActiveRecord::XmlSerializer.new(self, options)
|
36
|
+
builder = serializer.builder
|
37
|
+
key = xml_cache_key(serializer.options)
|
38
|
+
fetch = Rails.cache.fetch(key) do
|
39
|
+
target = builder.target!
|
40
|
+
builder.instance_eval{ @target = '' }
|
41
|
+
value = block_given? ? serializer.to_s(&block) : serializer.to_s
|
42
|
+
builder.instance_eval{ @target = target }
|
43
|
+
value
|
44
|
+
end
|
45
|
+
builder.instance_eval{ @target << fetch }
|
38
46
|
else
|
39
47
|
to_xml_without_cache_flow(options, &block)
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
43
|
-
def to_json_with_cache_flow(options = {}
|
51
|
+
def to_json_with_cache_flow(options = {})
|
44
52
|
if cache_json?(options)
|
45
|
-
key = json_cache_key(options
|
46
|
-
|
47
|
-
|
53
|
+
key = json_cache_key(options)
|
54
|
+
Rails.cache.fetch(key) do
|
55
|
+
value = to_json_without_cache_flow(options)
|
56
|
+
value.duplicable? ? value.dup : value
|
57
|
+
end
|
48
58
|
else
|
49
|
-
to_json_without_cache_flow(options
|
59
|
+
to_json_without_cache_flow(options)
|
50
60
|
end
|
51
61
|
end
|
52
62
|
|
53
63
|
private
|
54
|
-
|
55
64
|
def cache_xml?(options, &block)
|
56
65
|
case
|
57
66
|
when block_given?, options.has_key?(:procs) then false
|
@@ -66,20 +75,20 @@ module LaserLemon
|
|
66
75
|
def cache_serialization?(options)
|
67
76
|
case
|
68
77
|
when options.has_key?(:cache) then options.delete(:cache)
|
69
|
-
else
|
78
|
+
else cache_serialization
|
70
79
|
end
|
71
80
|
end
|
72
81
|
|
73
82
|
def xml_cache_key(options)
|
74
83
|
level = options.has_key?(:builder) ? options[:builder].instance_eval{ @level } : nil
|
75
|
-
|
84
|
+
serialization_cache_key(:xml, options.except(:builder).merge(:level => level))
|
76
85
|
end
|
77
86
|
|
78
87
|
def json_cache_key(options)
|
79
|
-
|
88
|
+
serialization_cache_key(:json, options.merge(:include_root_in_json => include_root_in_json))
|
80
89
|
end
|
81
90
|
|
82
|
-
def
|
91
|
+
def serialization_cache_key(extension, options)
|
83
92
|
query = options.except(:cache).reject{|k,v| v.nil? }.to_query
|
84
93
|
["#{cache_key}.#{extension}", query].delete_if(&:blank?).join('?')
|
85
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: laserlemon-cache_flow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- laserlemon
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|