• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed Improvement to setSimpleCacheData Function

Chris D

XenForo developer
Staff member
#1
I have recently identified a possible improvement to this function which in some circumstances could potentially improve performance when a number of add-ons use the simple cache to store potentially a large amount of data.

Specifically it relates to a circumstance where data is set to false (to remove it from the cache) when perhaps the data already has been removed.

Although this probably shouldn't happen, I have seen it happen and in some scenarios it can cause a big issue for busy boards. Add-ons that cause such an issue could handle it better, but here's a potential safeguard that XenForo could use:

PHP:
public static function setSimpleCacheData($key, $value)
{
    $cache = self::get('simpleCache');

    if ($value === false)
    {
        unset($cache[$key]);
    }
    else
    {
        $cache[$key] = $value;
    }

    if ($cache !== self::get('simpleCache'))
    {
        XenForo_Model::create('XenForo_Model_DataRegistry')->set('simpleCache', $cache);
        self::set('simpleCache', $cache);
    }
}
All it does is compare the updated cache value with the original cache value so it gives the effect that if the original cache and the new cache is identical, the database isn't written to at all.
 

Mike

XenForo developer
Staff member
#2
No harm in changing it, though the add-ons in question really should be checking things like this.