本文整理汇总了PHP中Cache_Lite::setLifeTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache_Lite::setLifeTime方法的具体用法?PHP Cache_Lite::setLifeTime怎么用?PHP Cache_Lite::setLifeTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache_Lite
的用法示例。
在下文中一共展示了Cache_Lite::setLifeTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* Stores data into cache
*
* @param string $id
* @param mixed $data
* @param array (optional) $tags
* @param int (optional) $lifetime
* @return bool
*/
public function put($id, $data, array $tags = null, $lifetime = null)
{
if (($lifetime = (int) $lifetime) <= 0) {
$lifetime = null;
} elseif ($lifetime <= 2592000) {
$lifetime += VIVVO_START_TIME - 1;
} else {
$lifetime -= 1;
}
$this->cache_lite->setLifeTime($lifetime);
return $this->cache_lite->save($data, md5($id), 'vivvo_cache') === true;
}
示例2: glitre_search
function glitre_search($args)
{
global $config;
include 'inc.config.php';
include 'File/MARCXML.php';
$config = get_config($args['library']);
// Caching of search results
require 'Cache/Lite.php';
// Options for the cache
$options = array('cacheDir' => $config['base_path'] . 'cache/');
// Create a Cache_Lite object
$Cache_Lite = new Cache_Lite($options);
$cacheresult = 'nocache';
$records = array();
$single_record = false;
if (!empty($args['q'])) {
// Set default values if these two are empty, otherwise the cache won't work properly
$args['sort_by'] = $args['sort_by'] ? $args['sort_by'] : $config['default_sort_by'];
$args['sort_order'] = $args['sort_order'] ? $args['sort_order'] : $config['default_sort_order'];
// Calculate the cache id for the sorted results
$sorted_cache_id = 'sorted_' . $args['sort_by'] . '_' . $args['sort_order'] . '_' . $args['library'] . '_' . md5(strtolower($args['q']));
// Check if the results, sorted in the way we want them, are cached
if ($records = unserialize($Cache_Lite->get($sorted_cache_id))) {
// We found what we wanted
$cacheresult = 'sorted';
} else {
// Set an id for the search cache
$search_cache_id = 'search_' . $args['library'] . '_' . md5(strtolower($args['q']));
// Check if the raw results are already cached
$marcxml = '';
if ($marcxml = $Cache_Lite->get($search_cache_id)) {
// Found it!
$cacheresult = 'raw';
} else {
// Collect the MARCXML in a string
if (!empty($config['lib']['sru'])) {
// SRU
$query = urlencode(massage_input($args['q']));
$marcxml = get_sru($query);
} else {
// Z39.50
$query = "any=" . massage_input($args['q']);
$marcxml = get_z($query);
}
if (is_array($marcxml) && $marcxml['error']) {
return glitre_format_error($marcxml, $args['format']);
}
$Cache_Lite->setLifeTime($config['cache_time_search']);
$Cache_Lite->save($marcxml, $search_cache_id);
}
// Sort the records
$records = glitre_sort($marcxml, $args['sort_by'], $args['sort_order']);
$cacheablerecords = array();
foreach ($records as $record) {
// Remove the serialized objects
unset($record['marcobj']);
$cacheablerecords[] = $record;
}
$Cache_Lite->setLifeTime($config['cache_time_sorted']);
$Cache_Lite->save(serialize($cacheablerecords), $sorted_cache_id);
}
// Pick out the ones we actually want
// Note: Counting of pages starts on 0 (zero), so page=2 is actually the 3rd page of results
// Which page are we showing?
$page = $args['page'] ? $args['page'] : 0;
// How many reords should be displayed on a page?
// TODO: Parameters should probably be ablo to set this, but with a configurable default and upper limit
$per_page = $config['lib']['records_per_page'] ? $config['lib']['records_per_page'] : $config['records_per_page'];
// Get the location of the first record
$first_record = $page * $per_page;
// Get the total number of records
$num_of_records = count($records);
// Slice out the records that make up the page we are looking for
$records = array_slice($records, $first_record, $per_page);
// Calculate the position of the last record
$last_record = $first_record + count($records);
// Check the number of records after the slice
if (count($records) < 1) {
exit('Error: invalid result-page');
}
// Recreate the MARC objects if they are missing (because these records were revived from the cache)
$simplerecords = array();
foreach ($records as $record) {
if (!isset($record['marcobj'])) {
// Simplify the records to just an array of objects
$marc = new File_MARCXML($record['marcxml'], File_MARC::SOURCE_STRING);
$simplerecords[] = $marc->next();
} else {
$simplerecords[] = $record['marcobj'];
}
}
$records = $simplerecords;
} elseif (!empty($args['id'])) {
// Set an id for the single-record-by-id cache
$record_cache_id = 'record_' . $args['library'] . '_' . md5(strtolower($args['id']));
// Check if the record is already cached
$record = '';
if ($marcxml = $Cache_Lite->get($record_cache_id)) {
// Found it!
$cacheresult = 'record';
//.........这里部分代码省略.........