1. 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

Discussion in 'Resolved Bug Reports' started by Chris D, Aug 6, 2014.

  1. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
    Bob likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    No harm in changing it, though the add-ons in question really should be checking things like this.
     
    Bob likes this.

Share This Page