first commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Core\Repository\ApplicationCache;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Cache\Repository as Cache;
|
||||
|
||||
|
||||
class ApplicationCacheRepository
|
||||
{
|
||||
|
||||
private $cache;
|
||||
private $carbon;
|
||||
protected $cacheLife = 3600; // use second time ...
|
||||
private $cachePrefix = "gExtranetApi-";
|
||||
|
||||
public function __construct(
|
||||
Cache $cache,
|
||||
Carbon $carbon
|
||||
)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->carbon = $carbon;
|
||||
|
||||
}
|
||||
|
||||
private function createCacheStoreKey ( $cacheId )
|
||||
{
|
||||
return $this->cachePrefix.$cacheId;
|
||||
}
|
||||
|
||||
public function storeCache($cacheId , $param){
|
||||
$result = $param;
|
||||
$result["cacheId"] = $cacheId;
|
||||
$cacheSignature = $this->createCacheStoreKey($cacheId);
|
||||
$expiresAt = $this->carbon->addMinutes($this->cacheLife/60)->toDateTimeString();
|
||||
|
||||
$this->cache->put($cacheSignature, $result, $this->cacheLife);
|
||||
|
||||
return [
|
||||
'cacheId' => $cacheId,
|
||||
'expiresAt' => $expiresAt
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
public function getCache($cacheId){
|
||||
|
||||
$cacheId = $this->createCacheStoreKey($cacheId);
|
||||
$cacheInfo = $this->cache->get($cacheId);
|
||||
return $cacheInfo;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user