Created
February 18, 2011 14:42
-
-
Save flavorjones/833733 to your computer and use it in GitHub Desktop.
Cache small data sets by wrapping the table with an ActiveHash model.
This file contains 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
# | |
# 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