protected function static_acceleration_set($key, $data) {
        if ($this->staticaccelerationsize !== false && isset($this->staticaccelerationkeys[$key])) {
            $this->staticaccelerationcount--;
            unset($this->staticaccelerationkeys[$key]);
        }

        // We serialize anything that's not;
        // 1. A known scalar safe value.
        // 2. A definition that says it's simpledata.  We trust it that it doesn't contain dangerous references.
        // 3. An object that handles dereferencing by itself.
        if (is_scalar($data) || $this->definition->uses_simple_data()
                || $data instanceof cache_cached_object) {
            $this->staticaccelerationarray[$key]['data'] = $data;
            $this->staticaccelerationarray[$key]['serialized'] = false;
        } else {
            $this->staticaccelerationarray[$key]['data'] = serialize($data);
            $this->staticaccelerationarray[$key]['serialized'] = true;
        }
        if ($this->staticaccelerationsize !== false) {
            $this->staticaccelerationcount++;
            $this->staticaccelerationkeys[$key] = $key;
            if ($this->staticaccelerationcount > $this->staticaccelerationsize) {
                $dropkey = array_shift($this->staticaccelerationkeys);
                unset($this->staticaccelerationarray[$dropkey]);
                $this->staticaccelerationcount--;
            }
        }
        return true;
    }