Skip to content

Instantly share code, notes, and snippets.

@flavorjones
Created February 18, 2011 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flavorjones/833733 to your computer and use it in GitHub Desktop.
Save flavorjones/833733 to your computer and use it in GitHub Desktop.
Cache small data sets by wrapping the table with an ActiveHash model.
#
# Tired of Rails constructing SQL queries to keep loading the same
# small set of records over and over again?
#
# Well, cache those records in memory using ActiveHash!
# * https://github.com/zilkey/active_hash
#
require 'active_record'
require 'active_hash'
class StaticDataModel < ActiveHash::Base
class Actual < ActiveRecord::Base
set_table_name "static_data_models"
end
fields :name, :color
Actual.all.each do |record|
create :id => record.id, :name => record.name, :color => record.color
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment