本文整理汇总了PHP中Memcached::deleteMulti方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::deleteMulti方法的具体用法?PHP Memcached::deleteMulti怎么用?PHP Memcached::deleteMulti使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::deleteMulti方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clear
public function clear($prefix = '')
{
$prefix = $this->getNamespace() . $prefix;
$allKeys = self::$cache->getAllKeys();
$keys = array();
$prefixLength = strlen($prefix);
foreach ($allKeys as $key) {
if (substr($key, 0, $prefixLength) === $prefix) {
$keys[] = $key;
}
}
self::$cache->deleteMulti($keys);
return true;
}
示例2: deleteMulti
/**
* {@inheritdoc}
*/
public function deleteMulti(array $keys)
{
if (!method_exists($this->client, 'deleteMulti')) {
/*
* HHVM doesn't support deleteMulti, so I'll hack around it by
* setting all items expired.
* I could also delete() all items, but that would probably take
* more network requests (this version always takes 2)
*
* @see http://docs.hhvm.com/manual/en/memcached.deletemulti.php
*/
$values = $this->getMulti($keys);
$this->client->setMulti(array_fill_keys(array_keys($values), ''), time() - 1);
$return = array();
foreach ($keys as $key) {
$return[$key] = array_key_exists($key, $values);
}
return $return;
}
$result = (array) $this->client->deleteMulti($keys);
/*
* Contrary to docs (http://php.net/manual/en/memcached.deletemulti.php)
* deleteMulti returns an array of [key => true] (for successfully
* deleted values) and [key => error code] (for failures)
* Pretty good because I want an array of true/false, so I'll just have
* to replace the error codes by falses.
*/
foreach ($result as $key => $status) {
$result[$key] = $status === true;
}
return $result;
}
示例3: purge
/**
* Purges the cache deleting all items within it.
*
* @return boolean True on success. False otherwise.
*/
public function purge()
{
if ($this->isready) {
// Only use delete multi if we have the correct extension installed and if the memcached
// server is shared (flushing the cache is quicker otherwise).
$candeletemulti = $this->candeletemulti && $this->isshared;
if ($this->clustered) {
foreach ($this->setconnections as $connection) {
if ($candeletemulti) {
$keys = self::get_prefixed_keys($connection, $this->prefix);
$connection->deleteMulti($keys);
} else {
// Oh damn, this isn't multi-site safe.
$connection->flush();
}
}
} else {
if ($candeletemulti) {
$keys = self::get_prefixed_keys($this->connection, $this->prefix);
$this->connection->deleteMulti($keys);
} else {
// Oh damn, this isn't multi-site safe.
$this->connection->flush();
}
}
}
// It never fails. Ever.
return true;
}
示例4: clear
public function clear($prefix = '')
{
$prefix = $this->getNamespace() . $prefix;
$allKeys = self::$cache->getAllKeys();
if ($allKeys === false) {
// newer Memcached doesn't like getAllKeys(), flush everything
self::$cache->flush();
return true;
}
$keys = array();
$prefixLength = strlen($prefix);
foreach ($allKeys as $key) {
if (substr($key, 0, $prefixLength) === $prefix) {
$keys[] = $key;
}
}
if (method_exists(self::$cache, 'deleteMulti')) {
self::$cache->deleteMulti($keys);
} else {
foreach ($keys as $key) {
self::$cache->delete($key);
}
}
return true;
}
示例5: flush
/**
* {@inheritdoc}
*/
public function flush() : StorageInterface
{
if ($keys = $this->memcached->get($this->prefix)) {
$this->memcached->delete($this->prefix);
$this->memcached->deleteMulti(explode('|', $keys));
}
return $this;
}
示例6: deleteMulti
/**
* Removes multiple items from Memcached.
* If using memcached, this method requires php5-memcached package version >=2.0!
*
* @param array $keys of items to be removed
*
* @return bool true on success, also if memcached has been disabled
*/
public function deleteMulti(array $keys)
{
$keys2 = array();
foreach ($keys as $key) {
$keys2[] = md5($this->uniqId . '_' . $key);
}
return $this->memcached->deleteMulti($keys2);
}
示例7: deleteMulti
/**
* Removes multiple items from Memcached.
*
* @param string[] $keys of items to be removed
*
* @return bool true on success
*/
public function deleteMulti(array $keys)
{
if ($this->hasMultiDelete) {
return $this->memcached->deleteMulti($keys);
}
foreach ($keys as $key) {
$this->deleteItem($key);
}
return true;
}
示例8: removeTag
/**
* @inheritdoc
*/
public function removeTag($tag)
{
$tag = $this->prepareTag($tag);
if (!($value = $this->storage->get($tag))) {
return false;
}
$value = $this->unserialize($value);
$value[] = $tag;
$this->storage->deleteMulti($value);
return true;
}
示例9: deleteMany
/**
* Delete many keys from the cache at once
*
* @param array $keys An array of identifiers for the data
* @return array of boolean values that are true if the key was successfully
* deleted, false if it didn't exist or couldn't be removed.
*/
public function deleteMany($keys)
{
$cacheKeys = [];
foreach ($keys as $key) {
$cacheKeys[] = $this->_key($key);
}
$success = $this->_Memcached->deleteMulti($cacheKeys);
$return = [];
foreach ($keys as $key) {
$return[$key] = $success;
}
return $return;
}
示例10: internalRemoveItems
/**
* Internal method to remove multiple items.
*
* Options:
* - namespace <string>
* - The namespace to use
* - ignore_missing_items <boolean>
* - Throw exception on missing item
*
* @param array $keys
* @param array $options
* @return boolean
* @throws Exception\ExceptionInterface
*/
protected function internalRemoveItems(array &$normalizedKeys, array &$normalizedOptions)
{
// support for removing multiple items at once has been added in ext/memcached-2.0.0
if (static::$extMemcachedMajorVersion < 2) {
return parent::internalRemoveItems($normalizedKeys, $normalizedOptions);
}
$this->memcached->setOption(MemcachedResource::OPT_PREFIX_KEY, $normalizedOptions['namespace']);
$rsCodes = $this->memcached->deleteMulti($normalizedKeys);
$missingKeys = null;
foreach ($rsCodes as $key => $rsCode) {
if ($rsCode !== true && $rsCode != 0) {
if ($rsCode != MemcachedResource::RES_NOTFOUND) {
throw $this->getExceptionByResultCode($rsCode);
}
$missingKeys[] = $key;
}
}
if ($missingKeys && !$normalizedOptions['ignore_missing_items']) {
throw new Exception\ItemNotFoundException("Keys '" . implode("','", $missingKeys) . "' not found within namespace '{$normalizedOptions['namespace']}'");
}
return true;
}
示例11: removeItems
/**
* Remove items.
*
* Options:
* - namespace <string> optional
* - The namespace to use (Default: namespace of object)
*
* @param array $keys
* @param array $options
* @return boolean
* @throws Exception
*
* @triggers removeItems.pre(PreEvent)
* @triggers removeItems.post(PostEvent)
* @triggers removeItems.exception(ExceptionEvent)
*/
public function removeItems(array $keys, array $options = array())
{
$baseOptions = $this->getOptions();
if (!$baseOptions->getWritable()) {
return false;
}
$this->normalizeOptions($options);
$args = new ArrayObject(array('keys' => &$keys, 'options' => &$options));
try {
$this->memcached->setOption(MemcachedResource::OPT_PREFIX_KEY, $options['namespace']);
$rsCodes = array();
if (static::$extMemcachedMajorVersion >= 2) {
$rsCodes = $this->memcached->deleteMulti($keys);
} else {
foreach ($keys as $key) {
$rs = $this->memcached->delete($key);
if ($rs === false) {
$rsCodes[$key] = $this->memcached->getResultCode();
}
}
}
$missingKeys = null;
foreach ($rsCodes as $key => $rsCode) {
if ($rsCode !== true && $rsCode != 0) {
if ($rsCode != MemcachedResource::RES_NOTFOUND) {
throw $this->getExceptionByResultCode($rsCode);
} elseif (!$options['ignore_missing_items']) {
$missingKeys[] = $key;
}
}
}
if ($missingKeys) {
throw new Exception\ItemNotFoundException("Keys '" . implode("','", $missingKeys) . "' not found");
}
return true;
} catch (MemcachedException $e) {
throw new RuntimeException($e->getMessage(), 0, $e);
}
}
示例12: bulkRead
/**
* Reads from cache in bulk.
* @param string key
* @return array key => value pairs, missing items are omitted
*/
public function bulkRead(array $keys)
{
$prefixedKeys = array_map(function ($key) {
return urlencode($this->prefix . $key);
}, $keys);
$keys = array_combine($prefixedKeys, $keys);
$metas = $this->memcached->getMulti($prefixedKeys);
$result = [];
$deleteKeys = [];
foreach ($metas as $prefixedKey => $meta) {
if (!empty($meta[self::META_CALLBACKS]) && !Cache::checkCallbacks($meta[self::META_CALLBACKS])) {
$deleteKeys[] = $prefixedKey;
} else {
$result[$keys[$prefixedKey]] = $meta[self::META_DATA];
}
if (!empty($meta[self::META_DELTA])) {
$this->memcached->replace($prefixedKey, $meta, $meta[self::META_DELTA] + time());
}
}
if (!empty($deleteKeys)) {
$this->memcached->deleteMulti($deleteKeys, 0);
}
return $result;
}
示例13: deleteAllForKey
/**
* Delete of items for the set Key and throws exception if this is empty.
*
* @return bool
*
*/
public function deleteAllForKey()
{
$keys = $this->getAllKeys();
return parent::deleteMulti($keys);
}
示例14: mclear
/**
* Clear an array of values from the cache.
*
* @param array $key An array of keys to clear
*/
public function mclear(array $keys = array())
{
return $this->client->deleteMulti($keys);
}
示例15: dump_types
<?php
$m = new Memcached();
$m->addServer('localhost', '11211');
function dump_types($v, $k)
{
echo gettype($v) . "\n";
}
$keys = array(100, 'str');
array_walk($keys, 'dump_types');
$deleted = $m->deleteMulti($keys);
array_walk($keys, 'dump_types');