caching database stuff

Caspar wrote:

Hi I have a fairly large category stucture for this website I'm writing. So we have top level sections, which have categories and sub-categories etc for another 2 levels. These are stored in the db for easy admin with has_many and belongs_to relationships. I also use ferret for the majority of the searching. When the search results are returned I also return the number of hits per category aswell. This is all fine and ferret handles it very quickly. The slowest part of the whole search process (80%) by far is the database access for finding the various sub-categories to use in the ferret queries. Since these categories very rairly change, is it possible to load the whole category stucture into memory (maybe 1500 different categories in total) when the server is started? How do i do this? Or how do i setup an admin action that refreshes these global variables? Where do i store them etc..

If you add acts_as_nested_set to your category class you can fetch
all sub-categories of a category in one select. Add memcache and
you're golden.