65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
defined('IN_IA') or exit('Access Denied');
|
|
use phprs\ezsql\Sql;
|
|
|
|
// 读取指定的系统缓存项 core_cache表中
|
|
function cache_read($key,$db) {
|
|
$val = Sql::select('syweb_core_cache.`value`')
|
|
->from('syweb_core_cache')
|
|
->where('syweb_core_cache.`key`=?', $key)
|
|
->get($db ,null);
|
|
if(count($val)>0){
|
|
return iunserializer($val[0]["value"]);
|
|
}
|
|
}
|
|
|
|
|
|
function cache_search($prefix,$db) {
|
|
$rs = Sql::select('syweb_core_cache.*')
|
|
->from('syweb_core_cache')
|
|
->where('syweb_core_cache.`key` like ?', "{$prefix}%")
|
|
->get($db ,null);
|
|
|
|
$result = array();
|
|
foreach ((array)$rs as $v) {
|
|
$result[$v['key']] = iunserializer($v['value']);
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// 存储系统缓存
|
|
function cache_write($key, $data,$db,$pdo) {
|
|
if (empty($key) || !isset($data)) {
|
|
return false;
|
|
}
|
|
$record = array();
|
|
$record['`key`'] = $key;
|
|
$record['`value`'] = iserializer($data);
|
|
|
|
$id = Sql::replaceInto('syweb_core_cache')->values($record)->exec($pdo)->lastInsertId();
|
|
return $id;
|
|
}
|
|
|
|
|
|
function cache_delete($key) {
|
|
return Sql::deleteFrom('syweb_core_cache')->where('`key`=?',$key)->exec($pdo);
|
|
}
|
|
|
|
|
|
function cache_clean($prefix = '') {
|
|
global $_W;
|
|
if (empty($prefix)) {
|
|
$sql = 'DELETE FROM ' . tablename('core_cache');
|
|
$result = pdo_query($sql);
|
|
if ($result) {
|
|
unset($_W['cache']);
|
|
}
|
|
} else {
|
|
$sql = 'DELETE FROM ' . tablename('core_cache') . ' WHERE `key` LIKE :key';
|
|
$params = array();
|
|
$params[':key'] = "{$prefix}:%";
|
|
$result = pdo_query($sql, $params);
|
|
}
|
|
return $result;
|
|
}
|