# Caching computations on ActiveRecords

**URL:** <https://www.ruby-forum.com/t/caching-computations-on-activerecords/129723>\
**Category:** Rails\
**Created:** [February 21, 2008, 12:54am UTC](https://www.ruby-forum.com/t/caching-computations-on-activerecords/129723 "2008-02-21T00:54:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin\_cline](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3d9bf3/32.png) [@kevin\_cline](https://www.ruby-forum.com/u/kevin_cline)\
**Post date:** [February 21, 2008, 12:54am UTC](https://www.ruby-forum.com/t/caching-computations-on-activerecords/129723/1 "2008-02-21T00:54:52Z")

</div>

I have arrived at the following idiom for caching certain expensive  
computations on ActiveRecord subclasses:

def expensive  
@expensive = hairy\_database\_query\_or\_something  
end

def reload  
@expensive = nil  
super  
end

It works, but I’m vaguely unhappy about it. Is there a better way?
