Esempio n. 1
0
 /**
  * Replaces troublesome characters with underscores and prefixes if necessary
  *
  * @param   string  $id  of cache to sanitize
  * @return  string
  */
 protected function _sanitize_id($id)
 {
     static $prefix = null;
     if (is_null($prefix)) {
         $prefix = Arr::get($this->_config, 'prefix', '');
     }
     return parent::_sanitize_id($prefix . $id);
 }
Esempio n. 2
0
 /**
  * Deletes all caches Responses from all attached decorators.
  * 
  * Beware that if a decorator uses a cache which is used by other parts of the
  * system, or other systems. This will delete ALL cache entries, flushing the cache.
  *
  *     // Delete all responses from this decorator
  *     $decorator->delete_all();
  *
  * @return  boolean
  */
 public function delete_all()
 {
     return $this->_cache->delete_all();
 }
Esempio n. 3
0
 public function delete_all()
 {
     return parent::delete_all();
 }
Esempio n. 4
0
 private function selectExecute()
 {
     $select = DB::select()->from($this->table);
     foreach ($this->where as $key => $value) {
         $select->where($key, '=', $value);
     }
     if ($this->cached) {
         $keycache = $this->getKeyCached();
         $cache = Kohana_Cache::instance('memcache')->get($keycache);
         if ($cache !== null) {
             return $cache;
         }
     }
     if ($this->limit == 1) {
         $select = $select->execute()->current();
     } else {
         $select = $select->execute()->as_array();
     }
     if ($this->cached) {
         Kohana_Cache::instance('memcache')->set($keycache, $select, $this->cached);
     }
     if ($select) {
         return $select;
     }
     return false;
 }
Esempio n. 5
0
 /**
  * Load a circuit from the driver
  *
  * @param   string   circuit to load from the driver
  * @return  array
  */
 public function load($circuit_name)
 {
     return $this->_cache->load($this->_create_cache_key($circuit_name));
 }
Esempio n. 6
0
 /**
  * (non-PHPdoc)
  * @see modules/auth/classes/kohana/Kohana_Database_Mysql#query()
  */
 public function query($type, $sql, $as_object = FALSE, array $params = NULL)
 {
     if (isset($params['caching'])) {
         $this->_allow_caching = $params['caching'];
     }
     if ($this->_allow_caching === TRUE) {
         list($auto_type, $tags) = $this->_get_tables($sql);
     }
     $cache_key = $this->get_prefix('Database::query("' . $sql . '")');
     $result = FALSE;
     // Make sure the database is connected
     $this->_connection or $this->connect();
     if (!empty($this->_config['connection']['persistent']) and $this->_config['connection']['database'] !== Database_MySQL::$_current_databases[$this->_connection_id]) {
         // Select database on persistent connections
         $this->_select_db($this->_config['connection']['database']);
     }
     $from_cache = TRUE;
     if ($this->_allow_caching !== TRUE or $type != Database::SELECT or ($result = $this->_cache_instance->get($cache_key)) === NULL) {
         $from_cache = FALSE;
         if (!empty($this->_config['profiling'])) {
             // Benchmark this query for the current instance
             $benchmark = Profiler::start("Database ({$this->_instance})", $sql);
         }
         $result = mysql_query($sql, $this->_connection);
         // Execute the query
         if ($result === FALSE) {
             if (isset($benchmark)) {
                 // This benchmark is worthless
                 Profiler::delete($benchmark);
             }
             throw new Database_Exception(mysql_errno($this->_connection), '[:code] :error ( :query )', array(':code' => mysql_errno($this->_connection), ':error' => mysql_error($this->_connection), ':query' => $sql));
         }
     }
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
     // Set the last query
     $this->last_query = $sql;
     if ($type === Database::SELECT) {
         if (is_resource($result)) {
             $returned = new Database_MySQL_Result($result, $sql, $as_object, $params);
             if ($this->_allow_caching === TRUE) {
                 $this->_cache_instance->set_with_tags($cache_key, $returned->as_array(), Kohana::$cache_life, $tags);
             }
         } else {
             $returned = new Database_Result_Cached($result, $sql, $as_object);
         }
         return $returned;
     } else {
         if ($this->_allow_caching === TRUE) {
             if (!empty($tags)) {
                 // Сброс кэша
                 foreach ($tags as $tag) {
                     $this->_cache_instance->delete_tag($tag, 0);
                 }
             }
         }
         if ($type === Database::INSERT or $type === Database::REPLACE) {
             // Return a list of insert id and rows created
             return array(mysql_insert_id($this->_connection), mysql_affected_rows($this->_connection));
         } else {
             // Return the number of rows affected
             return mysql_affected_rows($this->_connection);
         }
     }
     return $result;
 }