Module: ActionController::Caching::Fragments
- Defined in:
- lib/interlock/action_controller.rb
Instance Method Summary collapse
-
#read_fragment(key, options = nil) ⇒ Object
Replaces Rail’s read_fragment method.
-
#write_fragment(key, block_content, options = nil) ⇒ Object
Replaces Rail’s write_fragment method.
Instance Method Details
#read_fragment(key, options = nil) ⇒ Object
Replaces Rail’s read_fragment method. Avoids checks for regex keys, which are unsupported, adds more detailed logging information, checks the local process cache before hitting memcached, and restores the content_for cache. Hits on memcached are also stored back locally to avoid duplicate requests.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/interlock/action_controller.rb', line 190 def read_fragment(key, = nil) return unless perform_caching if content = Interlock.local_cache.read(key, ) # Interlock.say key, "read from local cache" elsif content = fragment_cache_store.read(key, ) raise FragmentConsistencyError, "#{key} is not an Array" unless content.is_a? Array Interlock.say key, "read from memcached" Interlock.local_cache.write(key, content, ) else # Not found return nil end raise FragmentConsistencyError, "#{key}::content is not a String" unless content.first.is_a? String ||= {} # Note that 'nil' is considered true for :assign_content_for if [:assign_content_for] != false and content.last # Extract content_for variables content.last.each do |name, value| raise FragmentConsistencyError, "#{key}::content_for(:#{name}) is not a String" unless value.is_a? String # We'll just call the helper because that will handle nested view_caches properly. @template.send(:content_for, name, value) end end content.first end |
#write_fragment(key, block_content, options = nil) ⇒ Object
Replaces Rail’s write_fragment method. Avoids extra checks for regex keys which are unsupported, adds more detailed logging information, stores writes in the local process cache too to avoid duplicate memcached requests, and includes the content_for cache in the fragment.
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/interlock/action_controller.rb', line 170 def write_fragment(key, block_content, = nil) return unless perform_caching content = [block_content, @template.cached_content_for] fragment_cache_store.write(key, content, ) Interlock.local_cache.write(key, content, ) Interlock.say key, "wrote" block_content end |