-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDoctrineCacheHandler.php
More file actions
54 lines (47 loc) · 1.01 KB
/
Copy pathDoctrineCacheHandler.php
File metadata and controls
54 lines (47 loc) · 1.01 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
<?php
namespace Bolt\Session\Handler;
use Doctrine\Common\Cache\Cache;
/**
* Doctrine Cache Session Handler.
*
* @author Carson Full <carsonfull@gmail.com>
*/
class DoctrineCacheHandler extends AbstractHandler
{
/** @var Cache */
protected $cache;
/** @var int */
protected $ttl;
/**
* Constructor.
*
* @param Cache $cache The cache instance
* @param int $ttl Number of seconds before session expires
*/
public function __construct(Cache $cache, $ttl = 86400)
{
$this->cache = $cache;
$this->ttl = $ttl;
}
/**
* {@inheritdoc}
*/
public function read($sessionId)
{
return $this->cache->fetch($sessionId) ?: '';
}
/**
* {@inheritdoc}
*/
public function write($sessionId, $data)
{
return $this->cache->save($sessionId, $data, $this->ttl);
}
/**
* {@inheritdoc}
*/
public function destroy($sessionId)
{
return $this->cache->delete($sessionId);
}
}