Sha256: ab87d233a7cc7957adecdf63102024e811759ce4368f25bd1608005ba8a51fdc

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
# $Id: actions.rb 1 2005-04-11 11:04:30Z gmosx $

require 'fileutils'

module Nitro

# Adds support for caching.

module Caching

	# Action caching.

	module Actions 

		def self.append_features(base) # :nodoc: 
			super
			base.extend(ClassMethods)
		end

		module ClassMethods

			def cache_action(*actions)
				return unless caching_enabled
				
				before_filter(
					%{
						fragment_name = "\#\{@action_name\}\#{@request.query_string}"
						if fragment = Fragment.get(fragment_name)
							@out = fragment
							return
						end
					},
					:only => actions
				)
				
				after_filter(
					%{ 
						fragment_name = "\#\{@action_name\}\#{@request.query_string}"
						Fragment.put(fragment_name, @out) 
					},
					:only => actions
				)
			end
			
		end

		private 

		#--
		# FIXME: not implemented.
		#++
		
		def expire_action(*actions)
			return unless caching_enabled

			for action in [actions].flatten
				expire_fragment(action)
			end
		end

	end

end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nitro-0.16.0 lib/nitro/caching/actions.rb
nitro-0.17.0 lib/nitro/caching/actions.rb
nitro-0.18.0 lib/nitro/caching/actions.rb
nitro-0.18.1 lib/nitro/caching/actions.rb