[fix] Cache fixes #114

This commit is contained in:
Lkeme 2021-08-22 21:19:39 +08:00
parent af37f769d7
commit 5908419c38
4 changed files with 31 additions and 8 deletions

2
.gitignore vendored
View File

@ -26,13 +26,13 @@ conf/user1.ini
/conf/user.ini
/conf/test.ini
/conf/test1.ini
/log/
/src/backup/
script.php
# ignore all files in lib/
task/*
cache/*
log/*
# except for .gitkeep
!.gitkeep
# ignore TODO file in root directory,not subdir/TODO

3
log/.gitkeep Normal file
View File

@ -0,0 +1,3 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

View File

@ -36,11 +36,13 @@ class Cache
if (!isset($this->caches[$classname])) {
// 如果不存在缓存 初始化 "BHP_username_APP.dat"
$this->caches[$classname] = new Flintstone(
'BHP_' . getConf('username', 'login.account') . '_' . $classname, [
'dir' => APP_CACHE_PATH,
'gzip' => true,
'formatter' => new JsonFormatter()
]);
$this->removeSpecStr('BHP_' . getConf('username', 'login.account') . '_' . $classname),
[
'dir' => APP_CACHE_PATH,
'gzip' => true,
'formatter' => new JsonFormatter()
]
);
}
$this->cache = $this->caches[$classname];
return $this;
@ -72,7 +74,6 @@ class Cache
return $this->load($classname);
}
/**
* @use 获取值
* @param string $key
@ -99,4 +100,20 @@ class Cache
// $users->set('bob', ['email' => 'bob@site.com', 'password' => '123456']);
$this->getClassObj($extra_name)->cache->set($key, $data);
}
}
/**
* @use 去除特殊符号
* @param string $data
* @return string
*/
private function removeSpecStr(string $data): string
{
$specs = str_split(".,:;'*?~`!@#$%^&+=)(<>{}]|\/、");
foreach ($specs as $spec) {
$data = str_replace($spec, '', $data);
}
return $data;
}
}

View File

@ -0,0 +1,3 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep