UserModel::clearCache PHP Method

clearCache() public method

Delete cached data for user.
public clearCache ( integer | null $UserID, $CacheTypesToClear = null ) : boolean
$UserID integer | null The user to clear the cache for.
return boolean Returns **true** if the cache was cleared or **false** otherwise.
    public function clearCache($UserID, $CacheTypesToClear = null)
    {
        if (is_null($UserID) || !$UserID) {
            return false;
        }
        if (is_null($CacheTypesToClear)) {
            $CacheTypesToClear = ['user', 'roles', 'permissions'];
        }
        if (in_array('user', $CacheTypesToClear)) {
            $UserKey = formatString(self::USERID_KEY, ['UserID' => $UserID]);
            Gdn::cache()->remove($UserKey);
        }
        if (in_array('roles', $CacheTypesToClear)) {
            $UserRolesKey = formatString(self::USERROLES_KEY, ['UserID' => $UserID]);
            Gdn::cache()->remove($UserRolesKey);
        }
        if (in_array('permissions', $CacheTypesToClear)) {
            Gdn::sql()->put('User', ['Permissions' => ''], ['UserID' => $UserID]);
            $PermissionsIncrement = $this->getPermissionsIncrement();
            $UserPermissionsKey = formatString(self::USERPERMISSIONS_KEY, ['UserID' => $UserID, 'PermissionsIncrement' => $PermissionsIncrement]);
            Gdn::cache()->remove($UserPermissionsKey);
        }
        return true;
    }
UserModel