本文整理匯總了PHP中cache_definition::get_ttl方法的典型用法代碼示例。如果您正苦於以下問題:PHP cache_definition::get_ttl方法的具體用法?PHP cache_definition::get_ttl怎麽用?PHP cache_definition::get_ttl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cache_definition
的用法示例。
在下文中一共展示了cache_definition::get_ttl方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: set_many
/**
* Sends several key => value pairs to the cache.
*
* Using this function comes with potential performance implications.
* Not all cache stores will support get_many/set_many operations and in order to replicate this functionality will call
* the equivalent singular method for each item provided.
* This should not deter you from using this function as there is a performance benefit in situations where the cache store
* does support it, but you should be aware of this fact.
*
* <code>
* // This code will add four entries to the cache, one for each url.
* $cache->set_many(array(
* 'main' => 'http://moodle.org',
* 'docs' => 'http://docs.moodle.org',
* 'tracker' => 'http://tracker.moodle.org',
* 'qa' => ''http://qa.moodle.net'
* ));
* </code>
*
* @param array $keyvaluearray An array of key => value pairs to send to the cache.
* @return int The number of items successfully set. It is up to the developer to check this matches the number of items.
* ... if they care that is.
*/
public function set_many(array $keyvaluearray)
{
if ($this->loader !== false) {
// We have a loader available set it there as well.
// We have to let the loader do its own parsing of data as it may be unique.
$this->loader->set_many($keyvaluearray);
}
$data = array();
$simulatettl = $this->has_a_ttl() && !$this->store_supports_native_ttl();
$usestaticaccelerationarray = $this->use_static_acceleration();
foreach ($keyvaluearray as $key => $value) {
if (is_object($value) && $value instanceof cacheable_object) {
$value = new cache_cached_object($value);
} else {
if (!is_scalar($value)) {
// If data is an object it will be a reference.
// If data is an array if may contain references.
// We want to break references so that the cache cannot be modified outside of itself.
// Call the function to unreference it (in the best way possible).
$value = $this->unref($value);
}
}
if ($simulatettl) {
$value = new cache_ttl_wrapper($value, $this->definition->get_ttl());
}
$data[$key] = array('key' => $this->parse_key($key), 'value' => $value);
if ($usestaticaccelerationarray) {
$this->static_acceleration_set($data[$key]['key'], $value);
}
}
if ($this->perfdebug) {
cache_helper::record_cache_set($this->storetype, $this->definition->get_id());
}
return $this->store->set_many($data);
}
示例2: set_many
/**
* Sends several key => value pairs to the cache.
*
* Using this function comes with potential performance implications.
* Not all cache stores will support get_many/set_many operations and in order to replicate this functionality will call
* the equivalent singular method for each item provided.
* This should not deter you from using this function as there is a performance benefit in situations where the cache store
* does support it, but you should be aware of this fact.
*
* <code>
* // This code will add four entries to the cache, one for each url.
* $cache->set_many(array(
* 'main' => 'http://moodle.org',
* 'docs' => 'http://docs.moodle.org',
* 'tracker' => 'http://tracker.moodle.org',
* 'qa' => ''http://qa.moodle.net'
* ));
* </code>
*
* @param array $keyvaluearray An array of key => value pairs to send to the cache.
* @return int The number of items successfully set. It is up to the developer to check this matches the number of items.
* ... if they care that is.
*/
public function set_many(array $keyvaluearray)
{
$data = array();
$simulatettl = $this->has_a_ttl() && !$this->store_supports_native_ttl();
$usepersistcache = $this->is_using_persist_cache();
foreach ($keyvaluearray as $key => $value) {
if (is_object($value) && $value instanceof cacheable_object) {
$value = new cache_cached_object($value);
} else {
if (!is_scalar($value)) {
// If data is an object it will be a reference.
// If data is an array if may contain references.
// We want to break references so that the cache cannot be modified outside of itself.
// Call the function to unreference it (in the best way possible).
$value = $this->unref($value);
}
}
if ($simulatettl) {
$value = new cache_ttl_wrapper($value, $this->definition->get_ttl());
}
$data[$key] = array('key' => $this->parse_key($key), 'value' => $value);
if ($usepersistcache) {
$this->set_in_persist_cache($data[$key]['key'], $value);
}
}
if ($this->perfdebug) {
cache_helper::record_cache_set($this->storetype, $this->definition->get_id());
}
return $this->store->set_many($data);
}
示例3: set
/**
* Sets an item in the cache given its key and data value.
*
* @param string $key The key to use.
* @param mixed $data The data to set.
* @return bool True if the operation was a success false otherwise.
*/
public function set($key, $data)
{
if ($this->encode) {
// We must serialise this data.
$data = serialize($data);
}
return $this->connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl());
}
示例4: set_many
/**
* Sets many items in the cache in a single transaction.
*
* @param array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two
* keys, 'key' and 'value'.
* @return int The number of items successfully set. It is up to the developer to check this matches the number of items
* sent ... if they care that is.
*/
public function set_many(array $keyvaluearray)
{
$store = array();
foreach ($keyvaluearray as $pair) {
$store[$this->prepare_key($pair['key'])] = $pair['value'];
}
$result = apcu_store($store, null, $this->definition->get_ttl());
return count($keyvaluearray) - count($result);
}
示例5: set_many
/**
* Sets many items in the cache in a single transaction.
*
* @param array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two
* keys, 'key' and 'value'.
* @return int The number of items successfully set. It is up to the developer to check this matches the number of items
* sent ... if they care that is.
*/
public function set_many(array $keyvaluearray)
{
$count = 0;
foreach ($keyvaluearray as $pair) {
if ($this->connection->set($this->parse_key($pair['key']), $pair['value'], MEMCACHE_COMPRESSED, $this->definition->get_ttl())) {
$count++;
}
}
return $count;
}
示例6: set_many
/**
* Sets many items in the cache in a single transaction.
*
* @param array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two
* keys, 'key' and 'value'.
* @return int The number of items successfully set. It is up to the developer to check this matches the number of items
* sent ... if they care that is.
*/
public function set_many(array $keyvaluearray)
{
$pairs = array();
foreach ($keyvaluearray as $pair) {
$pairs[$pair['key']] = $pair['value'];
}
if ($this->connection->setMulti($pairs, $this->definition->get_ttl())) {
return count($keyvaluearray);
}
return 0;
}
示例7: set
/**
* Sets an item in the cache given its key and data value.
*
* @param string $key The key to use.
* @param mixed $data The data to set.
* @return bool True if the operation was a success false otherwise.
*/
public function set($key, $data)
{
if ($this->clustered) {
$status = true;
foreach ($this->setconnections as $connection) {
$status = $connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl()) && $status;
}
return $status;
}
return $this->connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl());
}
示例8: set
/**
* Sets an item in the cache given its key and data value.
*
* @param string $key The key to use.
* @param mixed $data The data to set.
* @return bool True if the operation was a success false otherwise.
*/
public function set($key, $data)
{
if ($this->encode) {
// We must serialise this data.
$data = serialize($data);
}
if ($this->clustered) {
$status = true;
foreach ($this->setconnections as $connection) {
$status = $connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl()) && $status;
}
return $status;
}
return $this->connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl());
}
示例9: set_many
/**
* Sets many items in the cache in a single transaction.
*
* @param array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two
* keys, 'key' and 'value'.
* @return int The number of items successfully set. It is up to the developer to check this matches the number of items
* sent ... if they care that is.
*/
public function set_many(array $keyvaluearray)
{
$pairs = array();
foreach ($keyvaluearray as $pair) {
$pairs[$pair['key']] = $pair['value'];
}
$status = true;
if ($this->clustered) {
foreach ($this->setconnections as $connection) {
$status = $connection->setMulti($pairs, $this->definition->get_ttl()) && $status;
}
} else {
$status = $this->connection->setMulti($pairs, $this->definition->get_ttl());
}
if ($status) {
return count($keyvaluearray);
}
return 0;
}
示例10: initialise
/**
* Initialises the cache.
*
* Once this has been done the cache is all set to be used.
*
* @param cache_definition $definition
*/
public function initialise(cache_definition $definition)
{
$this->storeid = $definition->generate_definition_hash();
$this->store =& self::register_store_id($this->name . '-' . $definition->get_id());
$this->ttl = $definition->get_ttl();
$maxsize = $definition->get_maxsize();
if ($maxsize !== null) {
// Must be a positive int.
$this->maxsize = abs((int) $maxsize);
$this->storecount = count($this->store);
}
$this->check_ttl();
}
示例11: has
/**
* Checks if the store has a record for the given key and returns true if so.
*
* @param string $key
* @return bool
*/
public function has($key)
{
$filename = $key . '.cache';
$maxtime = cache::now() - $this->definition->get_ttl();
if ($this->prescan) {
return array_key_exists($filename, $this->keys) && $this->keys[$filename] >= $maxtime;
}
$file = $this->file_path_for_key($key);
return file_exists($file) && ($this->definition->get_ttl() == 0 || filemtime($file) >= $maxtime);
}
示例12: initialise
/**
* Initialises the cache.
*
* Once this has been done the cache is all set to be used.
*
* @param cache_definition $definition
*/
public function initialise(cache_definition $definition)
{
$this->storeid = $definition->generate_definition_hash();
$this->store =& self::register_store_id($this->storeid);
$this->ttl = $definition->get_ttl();
}
示例13: set
/**
* Sets an item in the cache given its key and data value.
*
* @param string $key The key to use.
* @param mixed $data The data to set.
* @return bool True if the operation was a success false otherwise.
*/
public function set($key, $data)
{
return xcache_set($this->prefix . $key, $data, $this->definition->get_ttl());
}