Topic: Best way to pre-load all records of a model?

For example, imagine a Tree model representing a tree of nodes, like navigation.  It's a reasonable size, so I just want to shove the whole thing into memory and not worry about it.  What's the best way to do this?  For example, if I have an article and call article.node, it wouldn't know to use pre-loaded data.

What I've tried is to just shove the whole thing into a global variable, and always do manual lookups by ID into it, but there's gotta be a cleaner way to do this?

Re: Best way to pre-load all records of a model?

I have the exact same question. Did you end up finding an answer to this?

Re: Best way to pre-load all records of a model?

You dont every want to pre-load all of any database into mem. To me it would seem like a security risk, and slow performance down, im sure looking it up will do just fine.

Re: Best way to pre-load all records of a model?

This seems like a lot of risk with very little reward. Would you mind telling is why you want to do it this way? If a record changes in the database, how would you ensure that these changes get pushed to memory? Also, instead of global variables, consider storing them in class or module constants since at the very least, it will namespace them nicely (for example, if you have a model called foo, and you want to stash all the records, declare the constant within the Foo class).

Re: Best way to pre-load all records of a model?

So to handle our performance needs we use memcache to store records that do not change very often -- such as player stats.

We have activerecord callbacks that handle cache clearing/expiration when one of those records is updated.

It has resulted in us being able to server many more requests than we would otherwise using the same hardware.

At the end of the day, it works for us.

Play postseason fantasy sports at Fantasy Postseason - Written in RoR

Re: Best way to pre-load all records of a model?

I heard first time memcache for storing records & its works that's great, I will gonna try that !

miracle socks | miracle socks

Last edited by markhenry115 (2011-12-19 08:57:49)

Re: Best way to pre-load all records of a model?

Nice post that you have shared...Thanks for sharing your post..




How to Make a Website

Re: Best way to pre-load all records of a model?

why don't u use memcached ?
and use session variable to save the most used data ?

Re: Best way to pre-load all records of a model?

Yes caching is the standard for that particular reason, but I think its due more so to performance issues, rather than security.




________________________________________
My Blog

Last edited by randy112 (2013-06-30 13:19:56)

Re: Best way to pre-load all records of a model?

+1 for Edge Rider, would suggest this too!