3 namespace Friendica\Core\Session;
5 use Friendica\BaseObject;
6 use Friendica\Core\Cache;
7 use Friendica\Core\Session;
8 use SessionHandlerInterface;
10 require_once 'boot.php';
11 require_once 'include/text.php';
14 * SessionHandler using Friendica Cache
16 * @author Hypolite Petovan <mrpetovan@gmail.com>
18 class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
20 public function open($save_path, $session_name)
25 public function read($session_id)
27 if (empty($session_id)) {
31 $data = Cache::get('session:' . $session_id);
33 Session::$exists = true;
36 logger("no data for session $session_id", LOGGER_TRACE);
41 * @brief Standard PHP session write callback
43 * This callback updates the stored session data and/or the expiration depending
44 * on the case. Uses the Session::expire for existing session, 5 minutes
45 * for newly created session.
47 * @param string $session_id Session ID with format: [a-z0-9]{26}
48 * @param string $session_data Serialized session data
49 * @return boolean Returns false if parameters are missing, true otherwise
51 public function write($session_id, $session_data)
61 $return = Cache::set('session:' . $session_id, $session_data, Session::$expire);
66 public function close()
71 public function destroy($id)
73 $return = Cache::delete('session:' . $id);
78 public function gc($maxlifetime)