Best way to store 'global variable' hash?

I have to store a very large hierarchical data of website categories and
pages. What is the best way to store this? It will being used to
generate website navigation as well as must be loaded into dropdown
selections on forms. It is STATIC and will not change and database would
like to be avoided.

Where is best place for this?? A hash in environment.rb? Loaded into
memory?? Must be accessed fast performance is not an ISSUE but is a
consideration.

Thank you

I would create a model that has the information and the create a
CONSTANT in the model that loads the data. Then it will be loaded once
in production into memory and yuo will have to do some magic when you
are going to update the info… I did this for a model that was
holding us states…

class State < ActiveRecord::Base
NAMES_ABBREVIATIONS = self.find(:all, :order => :name).map do |s|
[s.name, s.abbreviation]
end
end

On Aug 24, 7:13 am, Joao S. [email protected]

You could create a simple object (somewhere in yer /lib) that contains
all
of the hard-coded configuration values and cache it using the built in
memory cache of rails:

Rails.cache.write(‘key’, myobj)

The object can then be retrieved using:

Rails.cache.read(‘key’)

The default cache store, ActiveSupport::Cache::MemoryStore, is not
shared
between rails server processes so the object will be cached in memory
for
each instance of rails you have running. This probably isn’t that big
of an
issue, if but you want to change your caching strategy you can modify
the
config.cache_store to tell rails to use a different type of caching.
Apparently not all types of caching support object caching, but
MemoryStore
does.

On Mon, Aug 24, 2009 at 10:13 AM, Joao S. <

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs