Exemplo n.º 1
0
 /**
  * Sets a key value pair into the static acceleration array.
  *
  * @param string $key The parsed key
  * @param mixed $data
  * @return bool
  */
 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;
 }
Exemplo n.º 2
0
 /**
  * Removes references where required.
  *
  * @param stdClass|array $data
  * @return mixed What ever was put in but without any references.
  */
 protected function unref($data)
 {
     if ($this->definition->uses_simple_data()) {
         return $data;
     }
     // Check if it requires serialisation in order to produce a reference free copy.
     if ($this->requires_serialisation($data)) {
         // Damn, its going to have to be serialise.
         $data = serialize($data);
         // We unserialise immediately so that we don't have to do it every time on get.
         $data = unserialize($data);
     } else {
         if (!is_scalar($data)) {
             // Its safe to clone, lets do it, its going to beat the pants of serialisation.
             $data = $this->deep_clone($data);
         }
     }
     return $data;
 }
Exemplo n.º 3
0
 /**
  * Initialises the cache.
  *
  * Once this has been done the cache is all set to be used.
  *
  * @param cache_definition $definition
  */
 public function initialise(cache_definition $definition)
 {
     $keyarray = $definition->generate_multi_key_parts();
     $this->storeid = $keyarray['mode'] . '/' . $keyarray['component'] . '/' . $keyarray['area'] . '/' . $keyarray['siteidentifier'];
     $this->store =& self::register_store_id($this->storeid);
     $maxsize = $definition->get_maxsize();
     $this->simpledata = $definition->uses_simple_data();
     if ($maxsize !== null) {
         // Must be a positive int.
         $this->maxsize = abs((int) $maxsize);
         $this->storecount = count($this->store);
     }
 }