3
* Copyright 2010-2014 Horde LLC (http://www.horde.org/)
5
* See the enclosed file COPYING for license information (LGPL). If you
6
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
9
* @copyright 2010-2014 Horde LLC
10
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
15
* Cache storage in a PHP session.
17
* @author Michael Slusarz <slusarz@horde.org>
19
* @copyright 2010-2014 Horde LLC
20
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
23
class Horde_Cache_Storage_Session extends Horde_Cache_Storage_Base
26
* Pointer to the session entry.
35
* @param array $params Optional parameters:
37
* - session: (string) Store session data in this entry.
38
* DEFAULT: 'horde_cache_session'
41
public function __construct(array $params = array())
43
$params = array_merge(array(
44
'sess_name' => 'horde_cache_session'
47
parent::__construct($params);
51
* Do initialization tasks.
53
protected function _initOb()
55
if (!isset($_SESSION[$this->_params['sess_name']])) {
56
$_SESSION[$this->_params['sess_name']] = array();
58
$this->_sess = &$_SESSION[$this->_params['sess_name']];
63
public function get($key, $lifetime = 0)
65
return $this->exists($key, $lifetime)
66
? $this->_sess[$key]['d']
72
public function set($key, $data, $lifetime = 0)
74
$this->_sess[$key] = array(
82
public function exists($key, $lifetime = 0)
84
if (isset($this->_sess[$key])) {
85
/* 0 means no expire. */
86
if (($lifetime == 0) ||
87
((time() - $lifetime) <= $this->_sess[$key]['l'])) {
91
unset($this->_sess[$key]);
99
public function expire($key)
101
if (isset($this->_sess[$key])) {
102
unset($this->_sess[$key]);
111
public function clear()
113
$this->_sess = array();