1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 * Session cache driver.
5 * Cache library config goes in the session.storage config entry:
6 * $config['storage'] = array(
10 * Lifetime does not need to be set as it is
11 * overridden by the session expiration setting.
13 * $Id: Cache.php 3769 2008-12-15 00:48:56Z zombor $
17 * @copyright (c) 2007-2008 Kohana Team
18 * @license http://kohanaphp.com/license.html
20 class Session_Cache_Driver implements Session_Driver {
25 public function __construct()
27 // Load Encrypt library
28 if (Kohana::config('session.encryption'))
30 $this->encrypt = new Encrypt;
33 Kohana::log('debug', 'Session Cache Driver Initialized');
36 public function open($path, $name)
38 $config = Kohana::config('session.storage');
42 // Load the default group
43 $config = Kohana::config('cache.default');
45 elseif (is_string($config))
49 // Test the config group name
50 if (($config = Kohana::config('cache.'.$config)) === NULL)
51 throw new Kohana_Exception('cache.undefined_group', $name);
54 $config['lifetime'] = (Kohana::config('session.expiration') == 0) ? 86400 : Kohana::config('session.expiration');
55 $this->cache = new Cache($config);
57 return is_object($this->cache);
60 public function close()
65 public function read($id)
68 if ($data = $this->cache->get($id))
70 return Kohana::config('session.encryption') ? $this->encrypt->decode($data) : $data;
73 // Return value must be string, NOT a boolean
77 public function write($id, $data)
80 $data = Kohana::config('session.encryption') ? $this->encrypt->encode($data) : $data;
82 return $this->cache->set($id, $data);
85 public function destroy($id)
88 return $this->cache->delete($id);
91 public function regenerate()
93 session_regenerate_id(TRUE);
95 // Return new session id
99 public function gc($maxlifetime)
101 // Just return, caches are automatically cleaned up
105 } // End Session Cache Driver