feat(Core): add optimize and complete code
This commit is contained in:
@@ -20,6 +20,10 @@ class Cache {
|
||||
* Get cached value
|
||||
*/
|
||||
public function get($key, $group = 'sodino') {
|
||||
if (!$this->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$full_key = $this->buildKey($key, $group);
|
||||
|
||||
// Check memory cache first
|
||||
@@ -42,6 +46,10 @@ class Cache {
|
||||
* Set cached value
|
||||
*/
|
||||
public function set($key, $value, $expiration = 3600, $group = 'sodino') {
|
||||
if (!$this->isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$full_key = $this->buildKey($key, $group);
|
||||
|
||||
// Set in memory cache
|
||||
@@ -134,4 +142,12 @@ class Cache {
|
||||
private function buildKey($key, $group) {
|
||||
return "sodino_{$group}_{$key}";
|
||||
}
|
||||
|
||||
private function isEnabled() {
|
||||
if (!class_exists(__NAMESPACE__ . '\Settings')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Settings::getInstance()->isCacheEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user