ActiveRecord: using a YAML file instead of a DB table

So, this may sound kind of “whacky”, but I’m trying to figure out a way
to populate an ActiveRecord object using YAML instead of a DB table.
I’m not even sure if this is actually feasible, but it sounds like a
good way to increase the performance of a project I’m working on.

For instance, I have a model called CmsModules that contains information
about the sections in a CMS. Modules are only added during development,
so the table will never be updated while in production. The way things
are currently set up, an SQL statement is executed on every page load in
order to grab that information. I figure this is unnecessary, and I’d
like to keep the same functionality without making those extra calls to
the database.

I figure that I could use a YAML file to store the module information,
therefore eliminating the need to access the database. Easy enough to
do using YAML::load, but the problem is that I need to keep a HABTM
relationship to the User model intact for access control. That’s where
I’m lost…

So, my question is this - is there any way to have legit ActiveRecord
objects populated from a YAML file, completely bypassing the database?

Andrew H. wrote:

So, this may sound kind of “whacky”, but I’m trying to figure out a way
to populate an ActiveRecord object using YAML instead of a DB table.

You must invent SQL-Ypath - a query notation for YAML that’s compatible
with SQL.

I’m not even sure if this is actually feasible, but it sounds like a
good way to increase the performance of a project I’m working on.

Such a language could never possibly be as performant as a tuned SQL
database.
Hordes of people work on those, for you.

For instance, I have a model called CmsModules that contains information
about the sections in a CMS. Modules are only added during development,
so the table will never be updated while in production. The way things
are currently set up, an SQL statement is executed on every page load in
order to grab that information. I figure this is unnecessary, and I’d
like to keep the same functionality without making those extra calls to
the database.

Have you profiled these page hits? Maybe the database already caches
things for
you; that’s it’s job.

Next, look up MemCache, to explicitly cache database hits.


Phlip