-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPsrCacheHandler.php
More file actions
62 lines (52 loc) · 1.29 KB
/
Copy pathPsrCacheHandler.php
File metadata and controls
62 lines (52 loc) · 1.29 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
58
59
60
61
62
<?php
namespace Bolt\Session\Handler;
use Psr\Cache\CacheItemPoolInterface;
/**
* PSR-6 Cache Session Handler.
*
* @author Carson Full <carsonfull@gmail.com>
*/
class PsrCacheHandler extends AbstractHandler
{
/** @var CacheItemPoolInterface */
protected $pool;
/** @var int */
protected $ttl;
/**
* Constructor.
*
* @param CacheItemPoolInterface $pool The cache instance
* @param int|null $ttl Number of seconds before session expires.
* Null for default value from cache pool.
*/
public function __construct(CacheItemPoolInterface $pool, $ttl = null)
{
$this->pool = $pool;
$this->ttl = $ttl;
}
/**
* {@inheritdoc}
*/
public function read($sessionId)
{
$item = $this->pool->getItem($sessionId);
return $item->isHit() ? $item->get() : '';
}
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
{
$item = $this->pool->getItem($sessionId);
$item->set($data);
$item->expiresAfter($this->ttl);
return $this->pool->save($item);
}
/**
* {@inheritdoc}
*/
public function destroy($sessionId)
{
return $this->pool->deleteItem($sessionId);
}
}