Created
May 3, 2010 19:20
-
-
Save tcocca/388482 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
has_many :authors | |
has_many :post_comments | |
attr_accessor :post_authors_cache, :post_comments_cache | |
def post_authors | |
@post_authors_cache ||= begin | |
process_post | |
@post_authors_cache | |
end | |
end | |
def post_comments | |
process_post if post_comments_cache.nil? | |
post_comments_cache | |
end | |
private | |
def process_post | |
#do some crazy stuff here and set the post_authors_cache | |
# some loop where you set two things and only loop through once | |
self.post_authors_cache = {} | |
self.post_comments_cache = {} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment