Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source
Show
Ignore:
Timestamp:
12/16/07 16:56:42 (10 months ago)
Author:
david
Message:

Introduce cache_key management and expansion

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2-1-caching/activerecord/lib/active_record/base.rb

    r8381 r8415  
    19481948        (id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes 
    19491949      end 
     1950       
     1951      # Returns a cache key that can be used to identify this record. Examples: 
     1952      # 
     1953      #   Product.new.cache_key     # => "products/new" 
     1954      #   Product.find(5).cache_key # => "products/5" (updated_at not available) 
     1955      #   Person.find(5).cache_key  # => "people/5-20071224150000" (updated_at available) 
     1956      def cache_key 
     1957        case  
     1958        when new_record? 
     1959          "#{self.class.name.tableize}/new" 
     1960        when self[:updated_at] 
     1961          "#{self.class.name.tableize}/#{id}-#{updated_at.to_s(:number)}" 
     1962        else 
     1963          "#{self.class.name.tableize}/#{id}" 
     1964        end 
     1965      end 
    19501966 
    19511967      def id_before_type_cast #:nodoc: