Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 8b99df826c3b6cf56a1caaae5f931d50 > files > 235

ruby-actionpack-2.3.4-1mdv2010.0.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Caching::Actions</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Caching::Actions</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/action_controller/caching/actions_rb.html">
                lib/action_controller/caching/actions.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Action caching is similar to page caching by the fact that the entire
output of the response is cached, but unlike page caching, every request
still goes through the Action Pack. The key benefit of this is that filters
are run before the cache is served, which allows for authentication and
other restrictions on whether someone is allowed to see the cache. Example:
</p>
<pre>
  class ListsController &lt; ApplicationController
    before_filter :authenticate, :except =&gt; :public
    caches_page   :public
    caches_action :index, :show, :feed
  end
</pre>
<p>
In this example, the public action doesn&#8216;t require authentication, so
it&#8216;s possible to use the faster page caching method. But both the
show and feed action are to be shielded behind the authenticate filter, so
we need to implement those as action caches.
</p>
<p>
Action caching internally uses the fragment caching and an around filter to
do the job. The fragment cache is named according to both the current host
and the path. So a page that is accessed at <a
href="http://david.somewhere.com/lists/show/1">david.somewhere.com/lists/show/1</a>
will result in a fragment named
&quot;david.somewhere.com/lists/show/1&quot;. This allows the cacher to
differentiate between &quot;david.somewhere.com/lists/&quot; and
&quot;jamis.somewhere.com/lists/&quot; &#8212; which is a helpful way of
assisting the subdomain-as-account-key pattern.
</p>
<p>
Different representations of the same resource, e.g. <tt><a
href="http://david.somewhere.com/lists">david.somewhere.com/lists</a></tt>
and <tt><a
href="http://david.somewhere.com/lists.xml">david.somewhere.com/lists.xml</a></tt>
are treated like separate requests and so are cached separately. Keep in
mind when expiring an action cache that <tt>:action =&gt;
&#8216;lists&#8216;</tt> is not the same as <tt>:action =&gt;
&#8216;list&#8217;, :format =&gt; :xml</tt>.
</p>
<p>
You can set modify the default action cache path by passing a :cache_path
option. This will be passed directly to <a
href="Actions/ActionCachePath.html#M000083">ActionCachePath.path_for</a>.
This is handy for actions with multiple possible routes that should be
cached differently. If a block is given, it is called with the current
controller instance.
</p>
<p>
And you can also use :if (or :unless) to pass a Proc that specifies when
the action should be cached.
</p>
<p>
Finally, if you are using memcached, you can also pass :expires_in.
</p>
<pre>
  class ListsController &lt; ApplicationController
    before_filter :authenticate, :except =&gt; :public
    caches_page   :public
    caches_action :index, :if =&gt; Proc.new { |c| !c.request.format.json? } # cache if is not a JSON request
    caches_action :show, :cache_path =&gt; { :project =&gt; 1 }, :expires_in =&gt; 1.hour
    caches_action :feed, :cache_path =&gt; Proc.new { |controller|
      controller.params[:user_id] ?
        controller.send(:user_list_url, controller.params[:user_id], controller.params[:id]) :
        controller.send(:list_url, controller.params[:id]) }
  end
</pre>
<p>
If you pass :layout =&gt; false, it will only cache your action content. It
is useful when your layout has dynamic information.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000081">expire_action</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Actions/ClassMethods.html" class="link">ActionController::Caching::Actions::ClassMethods</a><br />
Class <a href="Actions/ActionCachePath.html" class="link">ActionController::Caching::Actions::ActionCachePath</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000081" class="method-detail">
        <a name="M000081"></a>

        <div class="method-heading">
          <a href="Actions.src/M000081.html" target="Code" class="method-signature"
            onclick="popupCode('Actions.src/M000081.html');return false;">
          <span class="method-name">expire_action</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>