Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8307

Show
Ignore:
Timestamp:
12/05/07 21:06:36 (10 months ago)
Author:
marcel
Message:

Enhance documentation coverage for fragment caching. Closes #7315 [bscofield]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r8302 r8307  
    11*SVN* 
     2 
     3* Enhance documentation coverage for fragment caching. Closes #7315 [bscofield] 
     4 
     5* Fix typo in number helper docs. Closes #7582 [josh] 
    26 
    37* Add many examples to PrototypeHelper documentation. Closes #7656 [jeremymcanally] 
  • trunk/actionpack/lib/action_controller/caching.rb

    r8226 r8307  
    308308    #   <% end %> 
    309309    # 
    310     # This cache will bind to the name of action that called it. So you would be able to invalidate it using 
    311     # <tt>expire_fragment(:controller => "topics", :action => "list")</tt> -- if that was the controller/action used. This is not too helpful 
    312     # if you need to cache multiple fragments per action or if the action itself is cached using <tt>caches_action</tt>. So instead we should 
    313     # qualify the name of the action used with something like: 
     310    # This cache will bind to the name of the action that called it, so if this code was part of the view for the topics/list action, you would  
     311    # be able to invalidate it using <tt>expire_fragment(:controller => "topics", :action => "list")</tt>.  
     312    #  
     313    # This default behavior is of limited use if you need to cache multiple fragments per action or if the action itself is cached using  
     314    # <tt>caches_action</tt>, so we also have the option to qualify the name of the cached fragment with something like: 
    314315    # 
    315316    #   <% cache(:action => "list", :action_suffix => "all_topics") do %> 
    316317    # 
    317     # That would result in a name such as "/topics/list/all_topics", which wouldn't conflict with any action cache and neither with another 
    318     # fragment using a different suffix. Note that the URL doesn't have to really exist or be callable. We're just using the url_for system 
    319     # to generate unique cache names that we can refer to later for expirations. The expiration call for this example would be 
    320     # <tt>expire_fragment(:controller => "topics", :action => "list", :action_suffix => "all_topics")</tt>. 
     318    # That would result in a name such as "/topics/list/all_topics", avoiding conflicts with the action cache and with any fragments that use a  
     319    # different suffix. Note that the URL doesn't have to really exist or be callable - the url_for system is just used to generate unique  
     320    # cache names that we can refer to when we need to expire the cache.  
     321    #  
     322    # The expiration call for this example is: 
     323    #  
     324    #   expire_fragment(:controller => "topics", :action => "list", :action_suffix => "all_topics") 
    321325    # 
    322326    # == Fragment stores 
    323327    # 
    324     # In order to use the fragment caching, you need to designate where the caches should be stored. This is done by assigning a fragment store 
    325     # of which there are four different kinds: 
    326     # 
    327     # * FileStore: Keeps the fragments on disk in the +cache_path+, which works well for all types of environments and shares the fragments for 
    328     #   all the web server processes running off the same application directory. 
     328    # By default, cached fragments are stored in memory. The available store options are: 
     329    # 
     330    # * FileStore: Keeps the fragments on disk in the +cache_path+, which works well for all types of environments and allows all  
     331    #   processes running from the same application directory to access the cached content. 
    329332    # * MemoryStore: Keeps the fragments in memory, which is fine for WEBrick and for FCGI (if you don't care that each FCGI process holds its 
    330333    #   own fragment store). It's not suitable for CGI as the process is thrown away at the end of each request. It can potentially also take 
     
    348351          cattr_reader :fragment_cache_store 
    349352 
     353          # Defines the storage option for cached fragments 
    350354          def self.fragment_cache_store=(store_option) 
    351355            store, *parameters = *([ store_option ].flatten) 
     
    361365      end 
    362366 
     367      # Given a name (as described in <tt>expire_fragment</tt>), returns a key suitable for use in reading,  
     368      # writing, or expiring a cached fragment. If the name is a hash, the generated name is the return 
     369      # value of url_for on that hash (without the protocol). 
    363370      def fragment_cache_key(name) 
    364371        name.is_a?(Hash) ? url_for(name).split("://").last : name 
     
    380387      end 
    381388 
     389      # Writes <tt>content</tt> to the location signified by <tt>name</tt> (see <tt>expire_fragment</tt> for acceptable formats) 
    382390      def write_fragment(name, content, options = nil) 
    383391        return unless perform_caching 
     
    390398      end 
    391399 
     400      # Reads a cached fragment from the location signified by <tt>name</tt> (see <tt>expire_fragment</tt> for acceptable formats) 
    392401      def read_fragment(name, options = nil) 
    393402        return unless perform_caching 
     
    406415      #   Ensure you do not specify start and finish in the regex (^$) because 
    407416      #   the actual filename matched looks like ./cache/filename/path.cache 
    408       #   Regexp expiration is not supported on caches which can't iterate over 
    409       #   all keys, such as memcached
     417      #   Regexp expiration is only supported on caches that can iterate over 
     418      #   all keys (unlike memcached)
    410419      def expire_fragment(name, options = nil) 
    411420        return unless perform_caching 
  • trunk/actionpack/lib/action_view/helpers/number_helper.rb

    r8301 r8307  
    11module ActionView 
    22  module Helpers #:nodoc: 
    3     # Provides methods for converting a numbers into formatted strings. 
     3    # Provides methods for converting numbers into formatted strings. 
    44    # Methods are provided for phone numbers, currency, percentage, 
    55    # precision, positional notation, and file size.