Sha256: d8cbbff76d074d5441cb8a723c0adfbe49ec54b0bb157be7435c2865aaf166b4

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

module Merb
  module Caching
  
    module Actions 
  
      def self.included(base) # :nodoc: 
        base.class_eval {
          def caching_enabled?
            @_caching_enabled ||= ::Merb::Server.cache_templates
          end
        }
        base.extend(ClassMethods)
      end
  
      module ClassMethods
  
        # Cache the given actions.
        
        def cache_action(*actions)
          return unless caching_enabled?
          before :_get_action_fragment, :only => actions        
          after :_store_action_fragment, :only => actions
        end
        
      end
  
      private 
  
      def _get_action_fragment
        fragment_name = "#{params[:action]}#{@request.query_string}"
        if fragment = ::Merb::Caching::Fragment.get(fragment_name)
          throw :halt, fragment
        end
      end
  
      def _store_action_fragment
        fragment_name = "#{params[:action]}#{@request.query_string}"
        ::Merb::Caching::Fragment.put(fragment_name, @body)
      end
  
      def caching_enabled?
        @_caching_enabled ||= ::Merb::Server.cache_templates
      end
      
      def expire_action(*actions)
        return unless caching_enabled?
        for action in [actions].flatten
          expire_fragment(action)
        end
      end
  
    end
  
  end
  
end  

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
merb-0.3.1 lib/merb/caching/action_cache.rb
merb-0.3.3 lib/merb/caching/action_cache.rb
merb-0.3.4 lib/merb/caching/action_cache.rb
merb-0.2.0 lib/merb/caching/action_cache.rb
merb-0.3.0 lib/merb/caching/action_cache.rb
merb-0.3.7 lib/merb/caching/action_cache.rb