存数据
boolean Driver_Cache_Driver_Database::set( string/array $key [, $data $value = null , $lifetime $lifetime = integer 3600 ] )
参数列表
参数 类型 描述 默认值 $key
string/array
支持多存 $value
$data
Value 多存时此项可空 null $lifetime
$lifetime
有效期,默认3600,即1小时,0表示不限制 integer 3600
boolean
public function set($key, $value = null, $lifetime = 3600)
{
if (IS_DEBUG)Core::debug()->info($key, 'database cache set key');
if ($lifetime>0)
{
$lifetime += TIME;
}
if (is_array($key))
{
foreach ($key as $k=>$v)
{
$k = $this->prefix . $k;
if (is_numeric($v))
{
$data = array
(
md5($k),
$k,
'',
$v,
$lifetime,
);
}
else
{
$this->_format_data($value[$k]);
$data = array
(
md5($k),
$k,
$value[$k],
0,
$lifetime,
);
}
$this->_handler->values($data);
}
}
else
{
$key = $this->prefix . $key;
if (is_numeric($value))
{
# 对于数值型数据,存在number字段里
$data = array
(
md5($key),
$key,
'',
$value,
$lifetime,
);
}
else
{
$this->_format_data($value);
$data = array
(
md5($key),
$key,
$value,
0,
$lifetime,
);
}
$this->_handler->values($data);
}
$rs = $this->_handler->columns(array('key', 'key_string', 'value', 'number', 'expire'))->replace($this->tablename);
if ($rs[0])
{
return true;
}
else
{
return false;
}
}