wiki:Cache system

Memory Cache System

This is for now just a project. This is to be followed in ticket  http://www.bevolunteer.org/trac/ticket/644 #644

The idea is to avoid the function which need to access to the words table (with the MOD_words object) or to the membertrads or forumtrads table to permanently access the database.

Of course in most of the case this result in a successful query in the datbase cache and this is not a real full load for mysql, but it is still a lot of CPU load and memory load regarding the result.
This can be improved by using some memory cache.

how should it work ?

The idea I have is to use php memcache (a description can be read there)  http://dk.php.net/manual/en/book.memcache.php.

A daemon must be installed first on the server and some libraries must be created for the specific needs of BeWelcome. These libraries should allow the BW function/object who retrieve data in words, membertrads or forumtrads to :

  • seek in the mem cache to see if a value, not expired, is allready available for the word code/membertrad entry or forumtrad entry for a give language:
    • if so this value is return
    • if not, the value is fetch from the database, copied in the cache and returned
  • mark expired the corresponding entry in the memcache for the word code/membertrad entry or forumtrad entry for a give language when it is updated
  • mark expired all memcache entries (in case we have doubt or if we want to reinitialize anything, because we made some change on the database using phpmyadmin for example).
  • display the remaining memory

In addition this function should be switchable on/off specifically for (according to Param->CacheWords, Param->CacheForumTrads, Param->CacheMemberTrads :

  • words
  • forumtrads
  • membertrads

benefit

Such system is expected to reduce load on the database by 90% (at least)

comment from tobixen: what advantages does the usage of MemCache give us as compared to implementing some simple caching system within the application?

jy : advantage is that the whole data will be loaded only once in memory (on the server) and shared by all sessions. For this we need a system to able to connect to this shared memory, this is what memcache provides.

Back to Documentation

what to cache?

words (static translations)

  • can be expected to grow much slower than the tables with user-generated content.
  • the words we have are reused very often
  • totally makes sense to cache them in memory, or in files.

forumtrads, membertrads

  • these texts have a more dynamic nature
  • this data can grow really big, and make the cache explode
  • if we want to cache this, we could also cache all DB data.
  • I think for now it is better to make the DB queries more efficient.

faq texts

  • a lot of text
  • single faq pages are not viewed that often
  • this is somewhere in between member trads and words. so, we can cache it, but don't need to.