3 namespace Friendica\Core\Session;
5 use Friendica\BaseObject;
6 use Friendica\Core\Cache;
7 use Friendica\Core\Logger;
8 use Friendica\Core\Session;
9 use SessionHandlerInterface;
12 * SessionHandler using Friendica Cache
14 * @author Hypolite Petovan <hypolite@mrpetovan.com>
16 class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
18 public function open($save_path, $session_name)
23 public function read($session_id)
25 if (empty($session_id)) {
29 $data = Cache::get('session:' . $session_id);
31 Session::$exists = true;
34 Logger::log("no data for session $session_id", Logger::TRACE);
39 * @brief Standard PHP session write callback
41 * This callback updates the stored session data and/or the expiration depending
42 * on the case. Uses the Session::expire for existing session, 5 minutes
43 * for newly created session.
45 * @param string $session_id Session ID with format: [a-z0-9]{26}
46 * @param string $session_data Serialized session data
47 * @return boolean Returns false if parameters are missing, true otherwise
49 public function write($session_id, $session_data)
59 $return = Cache::set('session:' . $session_id, $session_data, Session::$expire);
64 public function close()
69 public function destroy($id)
71 $return = Cache::delete('session:' . $id);
76 public function gc($maxlifetime)