-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLaravelCacheDriver.php
More file actions
57 lines (48 loc) · 1.25 KB
/
LaravelCacheDriver.php
File metadata and controls
57 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
declare(strict_types=1);
namespace Saloon\CachePlugin\Drivers;
use Saloon\CachePlugin\Contracts\Driver;
use Illuminate\Contracts\Cache\Repository;
use Saloon\CachePlugin\Data\CachedResponse;
class LaravelCacheDriver implements Driver
{
/**
* Constructor
*/
public function __construct(
protected Repository $store,
) {
//
}
/**
* Store the cached response on the driver.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function set(string $key, CachedResponse $cachedResponse): void
{
$this->store->set($key, serialize($cachedResponse), $cachedResponse->getTtl());
}
/**
* Get the cached response from the driver.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function get(string $cacheKey): ?CachedResponse
{
$data = $this->store->get($cacheKey);
if (empty($data)) {
return null;
}
return unserialize($data, ['allowed_classes' => true]);
}
/**
* Delete the cached response.
*
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function delete(string $cacheKey): void
{
$this->store->delete($cacheKey);
}
}