WEB: Increase cache duration and clear cache during site update

This commit is contained in:
Mataniko authored and Matan Bareket committed 2020-09-27 22:08:07 -04:00
1 parent a757a3bc14
commit 6816cdab5a
2 files changed
+14 -5

No files matched your search

+12 -4
View File
@@ -2,6 +2,7 @@
namespace ScummVM\Models;
use Phpfastcache\Helper\Psr16Adapter;
use Phpfastcache\Drivers\Redis\Config;
abstract class BasicModel
{
@@ -11,19 +12,26 @@ abstract class BasicModel
public function __construct()
{
if (is_null(self::$cache)) {
self::$cache = new Psr16Adapter('redis');
$config = new Config(['database' => 8]);
self::$cache = new Psr16Adapter('redis', $config);
}
}
protected function saveToCache($data, $key = '')
{
$cacheKey = str_replace("\\", "_", \get_called_class() . "_$key");
self::$cache->set($cacheKey, $data, 900);
if ($key) {
$key = "_$key";
}
$cacheKey = str_replace("\\", "_", \get_called_class() . $key);
self::$cache->set($cacheKey, $data, 3600);
}
protected function getFromCache($key = '')
{
$cacheKey = str_replace("\\", "_", \get_called_class() . "_$key");
if ($key) {
$key = "_$key";
}
$cacheKey = str_replace("\\", "_", \get_called_class() . $key);
$cachedData = self::$cache->get($cacheKey);
return $cachedData;
}