Beispiel #1
0
function pdb_get_data($key, $provider, $arguments = [])
{
    $mc_handler = memcache_pconnect(MC_HOST);
    $value = memcache_get($mc_handler, $key);
    if ($value !== false) {
        return $value;
    } else {
        $locking_key = 'lock_' . $key;
        $locking_value = microtime(true);
        for ($i = 0; $i < MC_LOCK_DELAY * 1000 / MC_SLEEP_TIME + 1; $i++) {
            $lock = memcache_add($mc_handler, $locking_key, $locking_value, 0, MC_LOCK_DELAY);
            if ($lock) {
                $value = call_user_func_array($provider, $arguments);
                memcache_set($mc_handler, $key, $value);
                memcache_delete($mc_handler, $locking_key);
                return $value;
            } else {
                usleep(MC_SLEEP_TIME);
                $value = memcache_get($mc_handler, $key);
                if ($value != false) {
                    return $value;
                }
            }
        }
    }
    return call_user_func_array($provider, $arguments);
}
Beispiel #2
0
function cache_delete($key, $timeout = 0)
{
    $connection = cache_connect();
    $res = memcache_delete($connection, (string) $key, (int) $timeout);
    memcache_close($connection);
    return $res;
}
Beispiel #3
0
 public function delete($name)
 {
     if (!is_resource($this->memcache)) {
         throw new \Exception("Memcached can't connect.");
     }
     return memcache_delete($this->memcache, $name);
 }
Beispiel #4
0
function cache_delete($key)
{
    if (!cache_connect()) {
        return false;
    }
    return memcache_delete(object('memcache'), $GLOBALS['config']['service']['server'] . '/' . $key);
}
Beispiel #5
0
 public function delItem($key)
 {
     if (empty($key)) {
         throw new CacheException('CACHE ERROR:key is empty');
     }
     return memcache_delete($this->cache, $key);
 }
Beispiel #6
0
function process_request()
{
    $item_id = isset($_POST['item_id']) ? intval($_POST['item_id']) : null;
    $item_name = isset($_POST['item_name']) ? $_POST['item_name'] : null;
    $item_price = isset($_POST['item_price']) ? $_POST['item_price'] : null;
    $item_description = isset($_POST['item_description']) ? $_POST['item_description'] : null;
    $item_img = isset($_POST['item_img']) ? $_POST['item_img'] : null;
    if (is_null($item_id) || $item_id <= 0) {
        die;
    }
    if (!is_null($item_name)) {
        $item_name = htmlspecialchars(trim($item_name));
        if ($item_name === '') {
            die;
        }
    }
    if (!is_null($item_price)) {
        if (!preg_match("/^\\d+([.,]\\d{1,2})?\$/", $item_price)) {
            die;
        }
    }
    if (!is_null($item_description)) {
        $item_description = htmlspecialchars(trim($item_description));
    }
    $item = db_get_item($item_id);
    if (!$item) {
        die;
    }
    $values = [];
    if (!is_null($item_name)) {
        $values['name'] = $item_name;
    }
    if (!is_null($item_price)) {
        $item_price = str_replace(',', '.', $item_price);
        $values['price'] = $item_price;
    }
    if (!is_null($item_description)) {
        $values['description'] = $item_description;
    }
    if (!is_null($item_img)) {
        $values['imgurl'] = $item_img;
    }
    if (!empty($values)) {
        db_update_item($item_id, $values);
        $mc_handler = memcache_connect('localhost');
        memcache_delete($mc_handler, get_page_cache_key($item_id));
        $min_price = min($item_price, $item['price']);
        pagination_rebuild_ids($mc_handler, $item_id, 1);
        if ($item_price == $item['price']) {
            $edited_pages_amount = 1;
        } else {
            $edited_pages_amount = 0;
        }
        pagination_rebuild_prices($mc_handler, $min_price, $edited_pages_amount);
        pagination_rebuild_prices($mc_handler, $min_price);
    }
    header('Location: /view_item.php?id=' . $item_id);
}
function memcache_version_del($memcache_obj, $key)
{
    global $config;
    if ($config['mcache']['version'] == 0) {
        return memcache_delete($memcache_obj, $key);
    } else {
        return $memcache_obj->delete($key);
    }
}
Beispiel #8
0
 static function register_static_delete($key)
 {
     $mmc = memcache_init();
     if ($mmc == false) {
         echo "那个坑爹的Memcache加载失败啦!笨蛋!\n";
     } else {
         memcache_delete($mmc, $key);
         return 1;
     }
 }
Beispiel #9
0
function SaeMemcacheDelete($key)
{
    //如果长度超出,则取末尾的234位
    if (strlen($key) > 234) {
        $key = substr($key, -234);
    }
    $mmc = memcache_init();
    if ($mmc == false) {
        return false;
    } else {
        return memcache_delete($mmc, $key);
    }
}
Beispiel #10
0
 function delete_search_keys()
 {
     $dbh = new PDO('mysql:dbname=' . AppConfig::gacv("AC_db") . ';host=' . AppConfig::gacv("AC_server"), AppConfig::gacv("AC_user"), AppConfig::gacv("AC_pass"));
     $memcache_obj = memcache_pconnect('localhost', 11211);
     $sql = sprintf("select search_key from %s ", "memcache_search_keys");
     $sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR, PDO::CURSOR_FWDONLY));
     //
     $sth->execute();
     $res = $sth->fetchAll(PDO::FETCH_BOTH);
     //echo $sql.$this->lookup_tbl_id_col;//
     foreach ($res as $ar) {
         memcache_delete($memcache_obj, $ar["search_key"], 0);
     }
     /* Delete all rows from the FRUIT table */
     $count = $dbh->exec("DELETE FROM memcache_search_keys");
 }
 public function del($key)
 {
     if (FALSE == $this->mc) {
         if (FALSE == $this->connect()) {
             return FALSE;
         }
     }
     $key = $this->keys_prefix . $key;
     if ($this->debug_mode) {
         $time = microtime(TRUE);
         $res = memcache_delete($this->mc, $key);
         $time = microtime(TRUE) - $time;
         $this->debug_info->time += $time;
         $this->debug_info->queries[] = (object) array('action' => 'DELETE', 'key' => $key, 'result' => $res ? 'TRUE' : 'FALSE', 'time' => number_format($time, 5, '.', ''));
         return $res;
     }
     return memcache_delete($this->mc, $key);
 }
Beispiel #12
0
 public static function delete($key, $name = 'default')
 {
     if (!App::instance()->get('cache_enable')) {
         return TRUE;
     }
     $client = self::client($key, $name);
     $ndx = self::$prefix . '_' . $key;
     switch (self::$engine) {
         case 'apc':
             return apc_delete($ndx);
         case 'redis':
             return $client->del($ndx);
             break;
         case 'memcache':
             return memcache_delete($client, $ndx);
             break;
         default:
             return @unlink($client . DS . $ndx);
     }
     return TRUE;
 }
Beispiel #13
0
function process_request()
{
    $item_id = isset($_GET['item_id']) ? intval($_GET['item_id']) : false;
    if ($item_id == false || $item_id <= 0) {
        api_wrong_args();
        return;
    }
    $item = db_get_item($item_id);
    if (!$item) {
        api_echo_as_json("Item not found", 'msg');
        return;
    }
    db_delete_item($item_id);
    $mc_handler = memcache_connect('localhost');
    pagination_rebuild_ids($mc_handler, $item['id']);
    pagination_rebuild_prices($mc_handler, $item['price']);
    if (memcache_get($mc_handler, 'total_rows') !== false) {
        memcache_decrement($mc_handler, 'total_rows');
    }
    api_echo_as_json('Item deleted', 'msg');
    memcache_delete($mc_handler, "item_" . $item_id);
}
Beispiel #14
0
<?php

header("Content-Type:text/html;charset=utf-8");
require_once 'Mysql.class.php';
/**
 * 要删除的用户
 */
$openid = "osvGYs3ntLy0YDpOxfLK-Duj3r50";
$sqlStr1 = "delete from tb_studentInfo where openid='{$openid}'";
//删除学生信息表
$sqlStr2 = "delete from tb_studentScore where openid='{$openid}'";
//删除学生成绩表
$sqlStr3 = "delete from tb_studentSyllabus where openid='{$openid}'";
//删除学生课表
$mmc = memcache_init();
$class_mysqlObj = new Class_mysql();
if ($class_mysqlObj->query($sqlStr1) && $class_mysqlObj->query($sqlStr2) && $class_mysqlObj->query($sqlStr3)) {
    if (memcache_delete($mmc, $openid . "password") && memcache_delete($mmc, $openid . "zjh")) {
        echo "该学生删除成功";
    } else {
        echo "删除缓存失败";
    }
} else {
    echo "删除数据库信息失败";
}
Beispiel #15
0
 public function memCacheDelete($key)
 {
     $key = $this->mckeyPre . $key;
     return memcache_delete($this->mc, $key);
 }
Beispiel #16
0
/**
 * 删除内存内容.
 *
 * @author dolphin
 *
 * @param string $key 内容KEY
 *
 * @return boolean布尔值(真|假)
 */
function delete_memcache_data($key)
{
    if (function_exists('memcache_connect')) {
        $memcache_object1 = @memcache_connect($GLOBALS['memcache_server1'], $GLOBALS['memcache_port']);
        $memcache_object2 = @memcache_connect($GLOBALS['memcache_server2'], $GLOBALS['memcache_port']);
    }
    if (is_object($memcache_object1)) {
        memcache_delete($memcache_object1, $key);
    }
    if (is_object($memcache_object2)) {
        memcache_delete($memcache_object2, $key);
    }
    return true;
}
 /**
  * @inheritDoc
  * @param String $key
  */
 public function delete($key)
 {
     $this->check();
     @memcache_delete($this->connection, $key);
 }
Beispiel #18
0
 /**
  *	Clear contents of cache backend
  *	@return bool
  *	@param $suffix string
  *	@param $lifetime int
  **/
 function reset($suffix = NULL, $lifetime = 0)
 {
     if (!$this->dsn) {
         return TRUE;
     }
     $regex = '/' . preg_quote($this->prefix . '.', '/') . '.+?' . preg_quote($suffix, '/') . '/';
     $parts = explode('=', $this->dsn, 2);
     switch ($parts[0]) {
         case 'apc':
             $info = apc_cache_info('user');
             foreach ($info['cache_list'] as $item) {
                 if (preg_match($regex, $item['info']) && $item['mtime'] + $lifetime < time()) {
                     apc_delete($item['info']);
                 }
             }
             return TRUE;
         case 'memcache':
             foreach (memcache_get_extended_stats($this->ref, 'slabs') as $slabs) {
                 foreach (array_filter(array_keys($slabs), 'is_numeric') as $id) {
                     foreach (memcache_get_extended_stats($this->ref, 'cachedump', $id) as $data) {
                         if (is_array($data)) {
                             foreach ($data as $key => $val) {
                                 if (preg_match($regex, $key) && $val[1] + $lifetime < time()) {
                                     memcache_delete($this->ref, $key);
                                 }
                             }
                         }
                     }
                 }
             }
             return TRUE;
         case 'wincache':
             $info = wincache_ucache_info();
             foreach ($info['ucache_entries'] as $item) {
                 if (preg_match($regex, $item['key_name']) && $item['use_time'] + $lifetime < time()) {
                     apc_delete($item['key_name']);
                 }
             }
             return TRUE;
         case 'xcache':
             return TRUE;
             /* Not supported */
         /* Not supported */
         case 'folder':
             if ($glob = @glob($parts[1] . '*')) {
                 foreach ($glob as $file) {
                     if (preg_match($regex, basename($file)) && filemtime($file) + $lifetime < time()) {
                         @unlink($file);
                     }
                 }
             }
             return TRUE;
     }
     return FALSE;
 }
Beispiel #19
0
 /**
  *	Clear contents of cache backend
  *	@return bool
  *	@param $suffix string
  *	@param $lifetime int
  **/
 function reset($suffix = NULL, $lifetime = 0)
 {
     if (!$this->dsn) {
         return TRUE;
     }
     $regex = '/' . preg_quote($this->prefix . '.', '/') . '.+?' . preg_quote($suffix, '/') . '/';
     $parts = explode('=', $this->dsn, 2);
     switch ($parts[0]) {
         case 'apc':
         case 'apcu':
             $info = apc_cache_info('user');
             if (!empty($info['cache_list'])) {
                 $key = array_key_exists('info', $info['cache_list'][0]) ? 'info' : 'key';
                 $mtkey = array_key_exists('mtime', $info['cache_list'][0]) ? 'mtime' : 'modification_time';
                 foreach ($info['cache_list'] as $item) {
                     if (preg_match($regex, $item[$key]) && $item[$mtkey] + $lifetime < time()) {
                         apc_delete($item[$key]);
                     }
                 }
             }
             return TRUE;
         case 'redis':
             $fw = Base::instance();
             $keys = $this->ref->keys($this->prefix . '.*' . $suffix);
             foreach ($keys as $key) {
                 $val = $fw->unserialize($this->ref->get($key));
                 if ($val[1] + $lifetime < time()) {
                     $this->ref->del($key);
                 }
             }
             return TRUE;
         case 'memcache':
             foreach (memcache_get_extended_stats($this->ref, 'slabs') as $slabs) {
                 foreach (array_filter(array_keys($slabs), 'is_numeric') as $id) {
                     foreach (memcache_get_extended_stats($this->ref, 'cachedump', $id) as $data) {
                         if (is_array($data)) {
                             foreach ($data as $key => $val) {
                                 if (preg_match($regex, $key) && $val[1] + $lifetime < time()) {
                                     memcache_delete($this->ref, $key);
                                 }
                             }
                         }
                     }
                 }
             }
             return TRUE;
         case 'wincache':
             $info = wincache_ucache_info();
             foreach ($info['ucache_entries'] as $item) {
                 if (preg_match($regex, $item['key_name']) && $item['use_time'] + $lifetime < time()) {
                     wincache_ucache_delete($item['key_name']);
                 }
             }
             return TRUE;
         case 'xcache':
             return TRUE;
             /* Not supported */
         /* Not supported */
         case 'folder':
             if ($glob = @glob($parts[1] . '*')) {
                 foreach ($glob as $file) {
                     if (preg_match($regex, basename($file)) && filemtime($file) + $lifetime < time()) {
                         @unlink($file);
                     }
                 }
             }
             return TRUE;
     }
     return FALSE;
 }
 /**
  * Remove a value in the remote cache store
  *
  * @access	public
  * @param	string		Cache unique key
  * @return	boolean		Cache removal successful
  */
 public function removeFromCache($key)
 {
     return memcache_delete($this->link, md5($this->identifier . $key));
 }
Beispiel #21
0
 public static function remove(string $key)
 {
     return memcache_delete($key);
 }
 /**
  * @inheritDoc
  *
  * @param String $key          
  */
 public function delete($key)
 {
     $this->connect();
     if ($this->mc) {
         $this->mc->delete($key, 0);
     } else {
         memcache_delete($this->connection, $key, 0);
     }
     $this->client->getLogger()->debug('Memcache cache delete', array('key' => $key));
 }
Beispiel #23
0
 public function url_stat($path, $flags)
 {
     $path = trim(substr($path, 8));
     $path = rtrim($path, '/');
     if (!$this->is_file_info_exists($path)) {
         return false;
     } else {
         if ($stat = memcache_get($this->mc(), $path . '.meta')) {
             $this->stat = unserialize($stat);
             if (is_array($this->stat)) {
                 if ($this->stat['mode'] == $this->dir_mode || ($c = memcache_get($this->mc(), $path))) {
                     return $this->stat;
                 } else {
                     memcache_delete($this->mc(), $path . '.meta');
                 }
             }
         }
         return false;
     }
 }
Beispiel #24
0
 /**
 		Delete variable from framework cache
 			@return bool
 			@param $name string
 			@param $quiet bool
 			@public
 	**/
 static function clear($name, $quiet = FALSE)
 {
     if (!self::$vars['CACHE']) {
         return TRUE;
     }
     if (is_null(self::$backend)) {
         // Auto-detect back-end
         self::detect();
         if (!self::prep()) {
             return FALSE;
         }
     }
     $key = $_SERVER['SERVER_NAME'] . '.' . $name;
     // Instruct back-end to clear data
     switch (self::$backend['type']) {
         case 'apc':
             $ok = !apc_exists($key) || apc_delete($key);
             break;
         case 'memcache':
             $ok = memcache_delete(self::$backend['id'], $key);
             break;
         case 'xcache':
             $ok = !xcache_isset($key) || xcache_unset($key);
             break;
         case 'folder':
             $ok = !is_file(self::$backend['id'] . $key) || @unlink(self::$backend['id'] . $key);
             break;
     }
     if (is_bool($ok) && !$ok) {
         if (!$quiet) {
             trigger_error(sprintf(self::TEXT_Clear, $name));
         }
         return FALSE;
     }
     // Check level-1 cache first
     if (isset(self::$buffer) && isset(self::$buffer[$name])) {
         unset(self::$buffer[$name]);
     }
     return TRUE;
 }
Beispiel #25
0
 public function del($name)
 {
     return memcache_delete($this->mmc, $name);
 }
Beispiel #26
0
 /**
  * @param string|array $key
  * @return bool
  */
 static function del($key)
 {
     if (is_array($key)) {
         foreach ($key as $k) {
             self::del($k);
         }
         return;
     }
     if (self::$localCache && isset(self::$_data[$key])) {
         unset(self::$_data[$key]);
     }
     $memcache_obj = self::_connect(self::getServer($key));
     return memcache_delete($memcache_obj, $key, 0);
 }
Beispiel #27
0
 /**
  * @inheritDoc
  * @param String $key
  */
 public function delete($key)
 {
     $this->connect();
     if ($this->mc) {
         $this->mc->delete($key, 0);
     } else {
         memcache_delete($this->connection, $key, 0);
     }
 }
Beispiel #28
0
function __pagination_concurrent_create_warm_page($mc_handler, $locking_key, $page_key, $query)
{
    $lock = memcache_add($mc_handler, $locking_key, microtime(true));
    if ($lock) {
        $item = db_get_row($query);
        memcache_delete($mc_handler, $locking_key);
        return $item;
    }
    //someone else is updating same page
    $value_changes = 0;
    $known_value = false;
    while (true) {
        $lock = memcache_get($mc_handler, $locking_key);
        if ($lock) {
            if ($known_value != $lock) {
                $value_changes++;
                if ($value_changes > 2) {
                    return memcache_get($mc_handler, $page_key);
                }
                $known_value = $lock;
            }
        } else {
            $lock = memcache_add($mc_handler, $locking_key, microtime(true));
            if ($lock) {
                $item = db_get_row($query);
                memcache_delete($mc_handler, $locking_key);
                return $item;
            } else {
                $value_changes++;
            }
        }
    }
}
Beispiel #29
0
 public function testDeleteNotThere()
 {
     $memcache = new Memcache();
     $request = new MemcacheDeleteRequest();
     $item = $request->addItem();
     $item->setKey("delete_key");
     $response = new MemcacheDeleteResponse();
     $response->addDeleteStatus(DeleteStatusCode::NOT_FOUND);
     $this->apiProxyMock->expectCall('memcache', 'Delete', $request, $response);
     $this->assertFalse(memcache_delete($memcache, "delete_key"));
     $this->apiProxyMock->verify();
 }
 /**
  * @inheritDoc
  * @param String $key
  */
 public function delete($key)
 {
     $this->connect();
     if ($this->mc) {
         $this->mc->delete($key, 0);
     } else {
         memcache_delete($this->connection, $key, 0);
     }
     $this->log('debug', 'Memcache cache delete', array('key' => $key));
 }