for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Mostafaznv\LaraCache\DTOs;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Mostafaznv\LaraCache\CacheEntity;
class CacheData
{
public function __construct(
public CacheStatus $status,
public ?int $expiration,
public mixed $value
) {}
public static function make(CacheStatus $status, int $ttl, mixed $value): self
$expiration = $ttl ? Carbon::now()->addSeconds($ttl)->unix() : null;
return new static($status, $expiration, $value);
}
public static function fromCache(CacheEntity $entity, string $prefix): self
$name = $prefix . '.' . $entity->name;
$value = Cache::store($entity->driver)->get($name, $entity->default);
if ($value === $entity->default) {
return self::make(CacheStatus::NOT_CREATED(), 0, $entity->default);
return $value;