3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core\Session\Handler;
24 use Friendica\Core\Cache\ICache;
25 use Friendica\Core\Session;
26 use SessionHandlerInterface;
29 * SessionHandler using Friendica Cache
31 class Cache implements SessionHandlerInterface
36 public function __construct(ICache $cache)
38 $this->cache = $cache;
41 public function open($save_path, $session_name)
46 public function read($session_id)
48 if (empty($session_id)) {
52 $data = $this->cache->get('session:' . $session_id);
54 Session::$exists = true;
62 * Standard PHP session write callback
64 * This callback updates the stored session data and/or the expiration depending
65 * on the case. Uses the Session::expire for existing session, 5 minutes
66 * for newly created session.
68 * @param string $session_id Session ID with format: [a-z0-9]{26}
69 * @param string $session_data Serialized session data
71 * @return boolean Returns false if parameters are missing, true otherwise
74 public function write($session_id, $session_data)
81 return $this->destroy($session_id);
84 return $this->cache->set('session:' . $session_id, $session_data, Session::$expire);
87 public function close()
92 public function destroy($id)
94 return $this->cache->delete('session:' . $id);
97 public function gc($maxlifetime)