Are the hashes faster than activerecord finds?

Hello, I need to store somewhere one hundred of static ressources text
field (internationalization).

I wonder if it better to put them in a database or in a hash defined at
app startup (in environment.rb)

I would go to the second one, but am I right ?

Thanks

Hashes will be faster. Why not load a hash from a table in
environment.rb?

On 5/15/06, Nuno [email protected] wrote:

Hello, I need to store somewhere one hundred of static ressources text
field (internationalization).

I wonder if it better to put them in a database or in a hash defined at
app startup (in environment.rb)

I would go to the second one, but am I right ?

Thanks

The easy answer is: benchmark :slight_smile:

Hashes of reasonable sizes that you keep in memory will be faster than
just about anything else. So, if there are some keyed pieces of
information that you use often and all over the place, you indeed
might want to put them inside a Hash constant loaded through
environment.rb. The Hash could be either plain Ruby Hash (e.g. a
constants.rb in /lib, then “require lib/constants” in environment.rb)
or something you load through Yaml (which is a bit cleaner).

Keeping the Hash in memory would be faster, but there’s a memory cost.
So if the Hash becomes large, this attitude loses its appeal. Also,
it’s a good solution for read-only pieces of information, not for
freely r/w operation (stuff like being thread-safe, locking etc. which
the database has for saving you from yourself). And if you don’t use
that Hash that often, consider an alternative or at least think about
clearing the memory space (by deleting all references to the Hash).

Thank you for your answer, I’ll go the hash way (loaded from the DB at
app startup)

The hash (which will be read only BTW) will not be that huge so I
presume that the memory cost will not be to high and will be shared
accross all http session