Documentation

Caching

In order to increase performance, FluxBB makes use of caching techniques in various places across the software.

This allows us to store results of frequently executed database queries for faster access directly on the file system.

Loading from cache

To load cached data, all you have to do is including the cache file (if it exists) – that will make a global variable available that contains the data:

// Load cached configuration
if (file_exists(FORUM_CACHE_DIR.'cache_config.php'))
    include FORUM_CACHE_DIR.'cache_config.php';

If the file does not exist, the cache has to be regenerated first.

Regenerating the cache

In order to not show old data on the forum, you need to make sure that the cache files are regenerated when you make changes to that data in the database. As an example, the generate_quickjump_cache() has to be called after changing group permissions for a specific forum.

This code shows how to regenerate the configuration cache, which should be done after updating config values in the database:

if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
    require PUN_ROOT.'include/cache.php';
 
// Regenerate the config cache
generate_config_cache();

The function names for the other caches are easy to guess:

  • generate_bans_cache()
  • generate_quickjump_cache()
  • generate_censoring_cache()
  • generate_stopwords_cache()
  • generate_users_info_cache()

The generate_quickjump_cache() function is special in that it can also accept a parameter to only regenerate the quickjump list for a certain user group. Just pass a valid group ID to the function to make use of that feature.