當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Memcache::now方法代碼示例

本文整理匯總了PHP中Memcache::now方法的典型用法代碼示例。如果您正苦於以下問題:PHP Memcache::now方法的具體用法?PHP Memcache::now怎麽用?PHP Memcache::now使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Memcache的用法示例。


在下文中一共展示了Memcache::now方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: write_record

 /**
  * Writes single cache record into DB.
  *
  * @param string $key  Cache key name
  * @param mxied  $data Serialized cache data 
  *
  * @param boolean True on success, False on failure
  */
 private function write_record($key, $data)
 {
     if (!$this->db) {
         return false;
     }
     if ($this->type == 'memcache' || $this->type == 'apc') {
         return $this->add_record($this->ckey($key), $data);
     }
     $key_exists = array_key_exists($key, $this->cache_sums);
     $key = $this->prefix . '.' . $key;
     // Remove NULL rows (here we don't need to check if the record exist)
     if ($data == 'N;') {
         $this->db->query("DELETE FROM " . $this->table . " WHERE user_id = ?" . " AND cache_key = ?", $this->userid, $key);
         return true;
     }
     // update existing cache record
     if ($key_exists) {
         $result = $this->db->query("UPDATE " . $this->table . " SET created = " . $this->db->now() . ", expires = " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL') . ", data = ?" . " WHERE user_id = ?" . " AND cache_key = ?", $data, $this->userid, $key);
     } else {
         // for better performance we allow more records for one key
         // so, no need to check if record exist (see rcube_cache::read_record())
         $result = $this->db->query("INSERT INTO " . $this->table . " (created, expires, user_id, cache_key, data)" . " VALUES (" . $this->db->now() . ", " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL') . ", ?, ?, ?)", $this->userid, $key, $data);
     }
     return $this->db->affected_rows($result);
 }
開發者ID:bbspike,項目名稱:sentora-core,代碼行數:33,代碼來源:rcube_cache.php

示例2: write_record

 /**
  * Writes single cache record into DB.
  *
  * @param string $key  Cache key name
  * @param mixed  $data Serialized cache data
  *
  * @param boolean True on success, False on failure
  */
 private function write_record($key, $data)
 {
     if (!$this->db) {
         return false;
     }
     // don't attempt to write too big data sets
     if (strlen($data) > $this->max_packet_size()) {
         trigger_error("rcube_cache: max_packet_size ({$this->max_packet}) exceeded for key {$key}. Tried to write " . strlen($data) . " bytes", E_USER_WARNING);
         return false;
     }
     if ($this->type == 'memcache' || $this->type == 'apc') {
         return $this->add_record($this->ckey($key), $data);
     }
     $key_exists = array_key_exists($key, $this->cache_sums);
     $key = $this->prefix . '.' . $key;
     // Remove NULL rows (here we don't need to check if the record exist)
     if ($data == 'N;') {
         $this->db->query("DELETE FROM {$this->table} WHERE `cache_key` = ?", $key);
         return true;
     }
     // update existing cache record
     if ($key_exists) {
         $result = $this->db->query("UPDATE {$this->table}" . " SET `created` = " . $this->db->now() . ", `expires` = " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL') . ", `data` = ?" . " WHERE `cache_key` = ?", $data, $key);
     } else {
         // for better performance we allow more records for one key
         // so, no need to check if record exist (see rcube_cache::read_record())
         $result = $this->db->query("INSERT INTO {$this->table}" . " (`created`, `expires`, `cache_key`, `data`)" . " VALUES (" . $this->db->now() . ", " . ($this->ttl ? $this->db->now($this->ttl) : 'NULL') . ", ?, ?)", $key, $data);
     }
     return $this->db->affected_rows($result);
 }
開發者ID:StudsPro,項目名稱:islandpeeps.com,代碼行數:38,代碼來源:rcube_cache_shared.php

示例3: write_record

 /**
  * Writes single cache record into DB.
  *
  * @param string $key  Cache key name
  * @param mixed  $data Serialized cache data
  *
  * @param boolean True on success, False on failure
  */
 private function write_record($key, $data)
 {
     if (!$this->db) {
         return false;
     }
     // don't attempt to write too big data sets
     if (strlen($data) > $this->max_packet_size()) {
         trigger_error("rcube_cache: max_packet_size ({$this->max_packet}) exceeded for key {$key}. Tried to write " . strlen($data) . " bytes", E_USER_WARNING);
         return false;
     }
     if ($this->type == 'memcache' || $this->type == 'apc') {
         $result = $this->add_record($this->ckey($key), $data);
         // make sure index will be updated
         if ($result) {
             if (!array_key_exists($key, $this->cache_sums)) {
                 $this->cache_sums[$key] = true;
             }
             $this->load_index();
             if (!$this->index_changed && !in_array($key, $this->index)) {
                 $this->index_changed = true;
             }
         }
         return $result;
     }
     $db_key = $this->prefix . '.' . $key;
     // Remove NULL rows (here we don't need to check if the record exist)
     if ($data == 'N;') {
         $result = $this->db->query("DELETE FROM {$this->table} WHERE `cache_key` = ?", $db_key);
         return !$this->db->is_error($result);
     }
     $key_exists = array_key_exists($key, $this->cache_sums);
     $expires = $this->ttl ? $this->db->now($this->ttl) : 'NULL';
     if (!$key_exists) {
         // Try INSERT temporarily ignoring "duplicate key" errors
         $this->db->set_option('ignore_key_errors', true);
         $result = $this->db->query("INSERT INTO {$this->table} (`expires`, `cache_key`, `data`)" . " VALUES ({$expires}, ?, ?)", $db_key, $data);
         $this->db->set_option('ignore_key_errors', false);
     }
     // otherwise try UPDATE
     if (!isset($result) || !($count = $this->db->affected_rows($result))) {
         $result = $this->db->query("UPDATE {$this->table} SET `expires` = {$expires}, `data` = ?" . " WHERE `cache_key` = ?", $data, $db_key);
         $count = $this->db->affected_rows($result);
     }
     return $count > 0;
 }
開發者ID:jimjag,項目名稱:roundcubemail,代碼行數:53,代碼來源:rcube_cache_shared.php


注:本文中的Memcache::now方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。