2010-07-25 18:27:45 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* Cache Session save handler. Allows saving session information into Cache.
|
2010-07-25 18:27:45 +00:00
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2010-07-25 18:27:45 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-07-25 18:27:45 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Model.Datasource.Session
|
2010-07-25 18:27:45 +00:00
|
|
|
* @since CakePHP(tm) v 2.0
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2010-07-25 18:27:45 +00:00
|
|
|
*/
|
2011-04-21 22:26:03 +00:00
|
|
|
|
|
|
|
App::uses('Cache', 'Cache');
|
2012-01-07 22:50:16 +00:00
|
|
|
App::uses('CakeSessionHandlerInterface', 'Model/Datasource/Session');
|
2011-04-21 22:26:03 +00:00
|
|
|
|
2010-07-25 18:27:45 +00:00
|
|
|
/**
|
|
|
|
* CacheSession provides method for saving sessions into a Cache engine. Used with CakeSession
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Model.Datasource.Session
|
2010-12-24 18:57:20 +00:00
|
|
|
* @see CakeSession for configuration information.
|
2010-07-25 18:27:45 +00:00
|
|
|
*/
|
|
|
|
class CacheSession implements CakeSessionHandlerInterface {
|
2012-03-04 19:18:04 +00:00
|
|
|
|
2010-07-25 18:27:45 +00:00
|
|
|
/**
|
|
|
|
* Method called on open of a database session.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2010-07-25 18:27:45 +00:00
|
|
|
*/
|
2010-09-06 04:43:58 +00:00
|
|
|
public function open() {
|
2010-07-25 18:27:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method called on close of a database session.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool Success
|
2010-07-25 18:27:45 +00:00
|
|
|
*/
|
2010-09-06 04:43:58 +00:00
|
|
|
public function close() {
|
2010-07-25 18:27:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method used to read from a database session.
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string $id The key of the value to read
|
2010-07-25 18:27:45 +00:00
|
|
|
* @return mixed The value of the key or false if it does not exist
|
|
|
|
*/
|
2010-09-06 04:43:58 +00:00
|
|
|
public function read($id) {
|
2015-12-22 21:19:51 +00:00
|
|
|
$data = Cache::read($id, Configure::read('Session.handler.config'));
|
2015-12-29 04:26:06 +00:00
|
|
|
|
|
|
|
if (!is_numeric($data) && empty($data)) {
|
2015-12-22 21:19:51 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return $data;
|
2010-07-25 18:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function called on write for database sessions.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $id ID that uniquely identifies session in database
|
2010-07-25 18:27:45 +00:00
|
|
|
* @param mixed $data The value of the data to be saved.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True for successful write, false otherwise.
|
2010-07-25 18:27:45 +00:00
|
|
|
*/
|
2010-09-06 04:43:58 +00:00
|
|
|
public function write($id, $data) {
|
2015-12-22 21:19:51 +00:00
|
|
|
return (bool)Cache::write($id, $data, Configure::read('Session.handler.config'));
|
2010-07-25 18:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method called on the destruction of a database session.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $id ID that uniquely identifies session in cache
|
|
|
|
* @return bool True for successful delete, false otherwise.
|
2010-07-25 18:27:45 +00:00
|
|
|
*/
|
2010-09-06 04:43:58 +00:00
|
|
|
public function destroy($id) {
|
2015-12-22 21:19:51 +00:00
|
|
|
return (bool)Cache::delete($id, Configure::read('Session.handler.config'));
|
2010-07-25 18:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-24 20:32:31 +00:00
|
|
|
* Helper function called on gc for cache sessions.
|
2010-07-25 18:27:45 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $expires Timestamp (defaults to current time)
|
|
|
|
* @return bool Success
|
2010-07-25 18:27:45 +00:00
|
|
|
*/
|
2010-09-06 04:43:58 +00:00
|
|
|
public function gc($expires = null) {
|
2015-12-22 21:19:51 +00:00
|
|
|
return (bool)Cache::gc(Configure::read('Session.handler.config'), $expires);
|
2012-03-24 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
2012-03-04 19:18:04 +00:00
|
|
|
}
|