/**
  * Sends a key => value pair to the cache.
  *
  * <code>
  * // This code will add four entries to the cache, one for each url.
  * $cache->set('main', 'http://moodle.org');
  * $cache->set('docs', 'http://docs.moodle.org');
  * $cache->set('tracker', 'http://tracker.moodle.org');
  * $cache->set('qa', 'http://qa.moodle.net');
  * </code>
  *
  * @param string|int $key The key for the data being requested.
  *      It can be any structure although using a scalar string or int is recommended in the interests of performance.
  *      In advanced cases an array may be useful such as in situations requiring the multi-key functionality.
  * @param mixed $data The data to set against the key.
  * @return bool True on success, false otherwise.
  */
 public function set($key, $data)
 {
     if ($this->perfdebug) {
         cache_helper::record_cache_set($this->storetype, $this->definition->get_id());
     }
     if ($this->loader !== false) {
         // We have a loader available set it there as well.
         // We have to let the loader do its own parsing of data as it may be unique.
         $this->loader->set($key, $data);
     }
     if (is_object($data) && $data instanceof cacheable_object) {
         $data = new cache_cached_object($data);
     } else {
         if (!is_scalar($data)) {
             // If data is an object it will be a reference.
             // If data is an array if may contain references.
             // We want to break references so that the cache cannot be modified outside of itself.
             // Call the function to unreference it (in the best way possible).
             $data = $this->unref($data);
         }
     }
     if ($this->has_a_ttl() && !$this->store_supports_native_ttl()) {
         $data = new cache_ttl_wrapper($data, $this->definition->get_ttl());
     }
     $parsedkey = $this->parse_key($key);
     if ($this->is_using_persist_cache()) {
         $this->set_in_persist_cache($parsedkey, $data);
     }
     return $this->store->set($parsedkey, $data);
 }