@@ -32,7 +32,7 @@ def partial!(*args)
32
32
# end
33
33
def cache! ( key = nil , options = { } )
34
34
if @context . controller . perform_caching
35
- value = :: Rails . cache . fetch ( _cache_key ( key , options ) , options ) do
35
+ value = _cache_fragment_for ( key , options ) do
36
36
_scope { yield self }
37
37
end
38
38
@@ -102,6 +102,25 @@ def _render_partial(options)
102
102
@context . render options
103
103
end
104
104
105
+ def _cache_fragment_for ( key , options , &block )
106
+ key = _cache_key ( key , options )
107
+ _read_fragment_cache ( key , options ) || _write_fragment_cache ( key , options , &block )
108
+ end
109
+
110
+ def _read_fragment_cache ( key , options = nil )
111
+ @context . controller . instrument_fragment_cache :read_fragment , key do
112
+ ::Rails . cache . read ( key , options )
113
+ end
114
+ end
115
+
116
+ def _write_fragment_cache ( key , options = nil )
117
+ @context . controller . instrument_fragment_cache :write_fragment , key do
118
+ yield . tap do |value |
119
+ ::Rails . cache . write ( key , value , options )
120
+ end
121
+ end
122
+ end
123
+
105
124
def _cache_key ( key , options )
106
125
key = _fragment_name_with_digest ( key , options )
107
126
0 commit comments