I am trying to cache some data from the database to reduce number of SQL queries to the database. Currently, what I am doing is that I will load a set of records from the database:
@records = Record.find(:all, :conditions => ["id < ?", 100])
and then iterate through this array to find the records that I really want:
@needed_records = Array.new
@records.each do |record|
if record.is_needed
@needed_records.push(record)
end
end
So that whenever I need, i can just pass @records instead of actually accessing the database.
My question is, is there any shortcoming doing it this way? Is there any better way to do the equivalent?