| Server IP : 69.72.244.102 / Your IP : 216.73.216.164 Web Server : LiteSpeed System : Linux s3434.fra1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64 User : konzalta ( 1271) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/konzalta/public_html/wp-content/plugins/wappointment/app/Repositories/ |
Upload File : |
<?php
namespace Wappointment\Repositories;
use Wappointment\Services\Flag;
use Wappointment\Services\Settings;
abstract class AbstractRepository implements \Wappointment\Repositories\RepositoryInterface
{
public $cache_key = '';
public $expiration = 0;
public function get()
{
if (empty(Settings::get('cache'))) {
return $this->query();
}
$cached_result = get_transient($this->getCacheKey());
return empty($cached_result) ? $this->init() : $cached_result;
}
/**
* Initing the cache only supposed to run once
*
* @return void
*/
protected function init()
{
$testFlag = 'cached_' . $this->getCacheKey();
$cache = null;
if (!Flag::get($testFlag)) {
$cache = $this->cache();
Flag::save($testFlag, \true);
}
return $cache;
}
public function cache()
{
$data = $this->query();
if (!empty($data)) {
set_transient($this->getCacheKey(), $data, $this->expiration);
}
return $data;
}
public function clear()
{
delete_transient($this->getCacheKey());
}
public function refresh()
{
$this->clear();
$this->cache();
}
private function getCacheKey()
{
return 'wappo_' . $this->cache_key;
}
}