| | 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 |
|---|