diff options
Diffstat (limited to 'kohana/libraries/drivers')
-rw-r--r-- | kohana/libraries/drivers/Cache/Memcache.php | 65 | ||||
-rw-r--r-- | kohana/libraries/drivers/Database/Mysqli.php | 6 | ||||
-rw-r--r-- | kohana/libraries/drivers/Database/Pgsql.php | 9 |
3 files changed, 30 insertions, 50 deletions
diff --git a/kohana/libraries/drivers/Cache/Memcache.php b/kohana/libraries/drivers/Cache/Memcache.php index f443b997..acd4c850 100644 --- a/kohana/libraries/drivers/Cache/Memcache.php +++ b/kohana/libraries/drivers/Cache/Memcache.php @@ -17,14 +17,11 @@ class Cache_Memcache_Driver implements Cache_Driver { protected $backend; protected $flags; - // The persistent lifetime value for expirations of 0 - protected $persistent_lifetime; - // Tags array - protected $tags; + protected static $tags; // Have the tags been changed? - protected $tags_changed = FALSE; + protected static $tags_changed = FALSE; public function __construct() { @@ -46,34 +43,34 @@ class Cache_Memcache_Driver implements Cache_Driver { or Kohana::log('error', 'Cache: Connection failed: '.$server['host']); } - // Set "persistent lifetime" value to one year - $this->persistent_lifetime = strtotime('now +1 year'); - // Load tags - $this->tags = $this->backend->get(self::TAGS_KEY); + self::$tags = $this->backend->get(self::TAGS_KEY); - if ( ! is_array($this->tags)) + if ( ! is_array(self::$tags)) { // Create a new tags array - $this->tags = array(); + self::$tags = array(); // Tags have been created - $this->tags_changed = TRUE; + self::$tags_changed = TRUE; } } public function __destruct() { - if ($this->tags_changed === TRUE) + if (self::$tags_changed === TRUE) { // Save the tags - $this->backend->set(self::TAGS_KEY, $this->tags, $this->flags, $this->persistent_lifetime); + $this->backend->set(self::TAGS_KEY, self::$tags, $this->flags, 0); + + // Tags are now unchanged + self::$tags_changed = FALSE; } } public function find($tag) { - if (isset($this->tags[$tag]) AND $results = $this->backend->get($this->tags[$tag])) + if (isset(self::$tags[$tag]) AND $results = $this->backend->get(self::$tags[$tag])) { // Return all the found caches return $results; @@ -95,22 +92,16 @@ class Cache_Memcache_Driver implements Cache_Driver { if ( ! empty($tags)) { // Tags will be changed - $this->tags_changed = TRUE; + self::$tags_changed = TRUE; foreach ($tags as $tag) { // Add the id to each tag - $this->tags[$tag][$id] = $id; + self::$tags[$tag][$id] = $id; } } - if ($lifetime === 0) - { - // Using an expiration of zero is unreliable, as memcache may delete - // it without warning. @see http://php.net/memcache_set - $lifetime = $this->persistent_lifetime; - } - else + if ($lifetime !== 0) { // Memcache driver expects unix timestamp $lifetime += time(); @@ -123,14 +114,14 @@ class Cache_Memcache_Driver implements Cache_Driver { public function delete($id, $tag = FALSE) { // Tags will be changed - $this->tags_changed = TRUE; + self::$tags_changed = TRUE; if ($id === TRUE) { if ($status = $this->backend->flush()) { // Remove all tags, all items have been deleted - $this->tags = array(); + self::$tags = array(); // We must sleep after flushing, or overwriting will not work! // @see http://php.net/manual/en/function.memcache-flush.php#81420 @@ -141,28 +132,28 @@ class Cache_Memcache_Driver implements Cache_Driver { } elseif ($tag === TRUE) { - if (isset($this->tags[$id])) + if (isset(self::$tags[$id])) { - foreach ($this->tags[$id] as $_id) + foreach (self::$tags[$id] as $_id) { // Delete each id in the tag $this->backend->delete($_id); } // Delete the tag - unset($this->tags[$id]); + unset(self::$tags[$id]); } return TRUE; } else { - foreach ($this->tags as $tag => $_ids) + foreach (self::$tags as $tag => $_ids) { - if (isset($this->tags[$tag][$id])) + if (isset(self::$tags[$tag][$id])) { // Remove the id from the tags - unset($this->tags[$tag][$id]); + unset(self::$tags[$tag][$id]); } } @@ -173,23 +164,23 @@ class Cache_Memcache_Driver implements Cache_Driver { public function delete_expired() { // Tags will be changed - $this->tags_changed = TRUE; + self::$tags_changed = TRUE; - foreach ($this->tags as $tag => $_ids) + foreach (self::$tags as $tag => $_ids) { foreach ($_ids as $id) { if ( ! $this->backend->get($id)) { // This id has disappeared, delete it from the tags - unset($this->tags[$tag][$id]); + unset(self::$tags[$tag][$id]); } } - if (empty($this->tags[$tag])) + if (empty(self::$tags[$tag])) { // The tag no longer has any valid ids - unset($this->tags[$tag]); + unset(self::$tags[$tag]); } } diff --git a/kohana/libraries/drivers/Database/Mysqli.php b/kohana/libraries/drivers/Database/Mysqli.php index 3d6bbfbf..13a81281 100644 --- a/kohana/libraries/drivers/Database/Mysqli.php +++ b/kohana/libraries/drivers/Database/Mysqli.php @@ -96,12 +96,6 @@ class Database_Mysqli_Driver extends Database_Mysql_Driver { throw new Kohana_Database_Exception('database.error', $this->show_error()); } - public function stmt_prepare($sql = '') - { - is_object($this->link) or $this->connect(); - return new Kohana_Mysqli_Statement($sql, $this->link); - } - public function escape_str($str) { if (!$this->db_config['escape']) diff --git a/kohana/libraries/drivers/Database/Pgsql.php b/kohana/libraries/drivers/Database/Pgsql.php index 9758de3c..62a33ad6 100644 --- a/kohana/libraries/drivers/Database/Pgsql.php +++ b/kohana/libraries/drivers/Database/Pgsql.php @@ -82,7 +82,8 @@ class Database_Pgsql_Driver extends Database_Driver { return self::$query_cache[$hash]; } - return new Pgsql_Result(pg_query($this->link, $sql), $this->link, $this->db_config['object'], $sql); + // Suppress warning triggered when a database error occurs (e.g., a constraint violation) + return new Pgsql_Result(@pg_query($this->link, $sql), $this->link, $this->db_config['object'], $sql); } public function set_charset($charset) @@ -161,12 +162,6 @@ class Database_Pgsql_Driver extends Database_Driver { return 'LIMIT '.$limit.' OFFSET '.$offset; } - public function stmt_prepare($sql = '') - { - is_object($this->link) or $this->connect(); - return new Kohana_Mysqli_Statement($sql, $this->link); - } - public function compile_select($database) { $sql = ($database['distinct'] == TRUE) ? 'SELECT DISTINCT ' : 'SELECT '; |