class Story < ActiveRecord::Base
acts_as_cached :include => :author
belongs_to :author
def after_save
expire_cache(id)
end
end
也可以这样:
class Story < ActiveRecord::Base
acts_as_cached
belongs_to :author
def author
Author.get_cache(author_id)
end
def after_save
expire_cache(id)
end
end
更容易理解
设置has_many关联
class Author < ActiveRecord::Base
acts_as_cached
has_many :stories
def after_save
expire_cache(id)
stories.each do |story|
story.expire_cache
end
end
end