3 namespace Friendica\Core\Session\Handler;
5 use Friendica\Core\Cache\ICache;
6 use Friendica\Core\Session;
7 use Psr\Log\LoggerInterface;
8 use SessionHandlerInterface;
11 * SessionHandler using Friendica Cache
13 * @author Hypolite Petovan <hypolite@mrpetovan.com>
15 final class Cache implements SessionHandlerInterface
19 /** @var LoggerInterface */
21 /** @var array The $_SERVER array */
24 public function __construct(ICache $cache, LoggerInterface $logger, array $server)
26 $this->cache = $cache;
27 $this->logger = $logger;
28 $this->server = $server;
31 public function open($save_path, $session_name)
36 public function read($session_id)
38 if (empty($session_id)) {
42 $data = $this->cache->get('session:' . $session_id);
44 Session::$exists = true;
48 $this->logger->notice('no data for session', ['session_id' => $session_id, 'uri' => $this->server['REQUEST_URI'] ?? '']);
54 * @brief Standard PHP session write callback
56 * This callback updates the stored session data and/or the expiration depending
57 * on the case. Uses the Session::expire for existing session, 5 minutes
58 * for newly created session.
60 * @param string $session_id Session ID with format: [a-z0-9]{26}
61 * @param string $session_data Serialized session data
63 * @return boolean Returns false if parameters are missing, true otherwise
66 public function write($session_id, $session_data)
76 return $this->cache->set('session:' . $session_id, $session_data, Session::$expire);
79 public function close()
84 public function destroy($id)
86 return $this->cache->delete('session:' . $id);
89 public function gc($maxlifetime)