githubtrue/backend/vendor/illuminate/session/CacheBasedSessionHandler.php @ cb15593b
1 |
<?php
|
---|---|
2 |
|
3 |
namespace Illuminate\Session; |
4 |
|
5 |
use SessionHandlerInterface; |
6 |
use Illuminate\Contracts\Cache\Repository as CacheContract; |
7 |
|
8 |
class CacheBasedSessionHandler implements SessionHandlerInterface |
9 |
{
|
10 |
/**
|
11 |
* The cache repository instance.
|
12 |
*
|
13 |
* @var \Illuminate\Contracts\Cache\Repository
|
14 |
*/
|
15 |
protected $cache; |
16 |
|
17 |
/**
|
18 |
* The number of minutes to store the data in the cache.
|
19 |
*
|
20 |
* @var int
|
21 |
*/
|
22 |
protected $minutes; |
23 |
|
24 |
/**
|
25 |
* Create a new cache driven handler instance.
|
26 |
*
|
27 |
* @param \Illuminate\Contracts\Cache\Repository $cache
|
28 |
* @param int $minutes
|
29 |
* @return void
|
30 |
*/
|
31 |
public function __construct(CacheContract $cache, $minutes) |
32 |
{
|
33 |
$this->cache = $cache; |
34 |
$this->minutes = $minutes; |
35 |
}
|
36 |
|
37 |
/**
|
38 |
* {@inheritdoc}
|
39 |
*/
|
40 |
public function open($savePath, $sessionName) |
41 |
{
|
42 |
return true; |
43 |
}
|
44 |
|
45 |
/**
|
46 |
* {@inheritdoc}
|
47 |
*/
|
48 |
public function close() |
49 |
{
|
50 |
return true; |
51 |
}
|
52 |
|
53 |
/**
|
54 |
* {@inheritdoc}
|
55 |
*/
|
56 |
public function read($sessionId) |
57 |
{
|
58 |
return $this->cache->get($sessionId, ''); |
59 |
}
|
60 |
|
61 |
/**
|
62 |
* {@inheritdoc}
|
63 |
*/
|
64 |
public function write($sessionId, $data) |
65 |
{
|
66 |
return $this->cache->put($sessionId, $data, $this->minutes); |
67 |
}
|
68 |
|
69 |
/**
|
70 |
* {@inheritdoc}
|
71 |
*/
|
72 |
public function destroy($sessionId) |
73 |
{
|
74 |
return $this->cache->forget($sessionId); |
75 |
}
|
76 |
|
77 |
/**
|
78 |
* {@inheritdoc}
|
79 |
*/
|
80 |
public function gc($lifetime) |
81 |
{
|
82 |
return true; |
83 |
}
|
84 |
|
85 |
/**
|
86 |
* Get the underlying cache repository.
|
87 |
*
|
88 |
* @return \Illuminate\Contracts\Cache\Repository
|
89 |
*/
|
90 |
public function getCache() |
91 |
{
|
92 |
return $this->cache; |
93 |
}
|
94 |
}
|