protected static function update_backup_cached_record($record, $extrarecord, $key, $existingrecord = null) {
        global $DB;
        // Update only if extrarecord is not empty.
        if (!empty($extrarecord)) {
            $extrarecord['id'] = self::$backupidsexist[$key];
            $DB->update_record('backup_ids_temp', $extrarecord);
            // Update existing cache or add new record to cache.
            if (isset(self::$backupidscache[$key])) {
                $record = array_merge((array)self::$backupidscache[$key], $extrarecord);
                self::$backupidscache[$key] = (object) $record;
            } else if (self::$backupidscachesize > 0) {
                if ($existingrecord) {
                    self::$backupidscache[$key] = $existingrecord;
                } else {
                    // Retrive record from database and cache updated records.
                    self::$backupidscache[$key] = $DB->get_record('backup_ids_temp', $record);
                }
                $record = array_merge((array)self::$backupidscache[$key], $extrarecord);
                self::$backupidscache[$key] = (object) $record;
                self::$backupidscachesize--;
            }
        }
    }