mirror of
https://github.com/friendica/friendica
synced 2025-04-25 01:50:11 +00:00
Add support for Memcached/Improve database cache
- Create Cache Driver interface - Update cache table fields - Add CacheSessionHandler
This commit is contained in:
parent
7bd4a52156
commit
3628b62aeb
9 changed files with 326 additions and 192 deletions
81
src/Core/Session/CacheSessionHandler.php
Normal file
81
src/Core/Session/CacheSessionHandler.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Core\Session;
|
||||
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Session;
|
||||
use SessionHandlerInterface;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'include/text.php';
|
||||
|
||||
/**
|
||||
* SessionHandler using Friendica Cache
|
||||
*
|
||||
* @author Hypolite Petovan <mrpetovan@gmail.com>
|
||||
*/
|
||||
class CacheSessionHandler extends BaseObject implements SessionHandlerInterface
|
||||
{
|
||||
public function open($save_path, $session_name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function read($session_id)
|
||||
{
|
||||
if (!x($session_id)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$data = Cache::get('session:' . $session_id);
|
||||
if (!empty($data)) {
|
||||
Session::$exists = true;
|
||||
return $data;
|
||||
}
|
||||
logger("no data for session $session_id", LOGGER_TRACE);
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Standard PHP session write callback
|
||||
*
|
||||
* This callback updates the stored session data and/or the expiration depending
|
||||
* on the case. Uses the Session::expire for existing session, 5 minutes
|
||||
* for newly created session.
|
||||
*
|
||||
* @param string $session_id Session ID with format: [a-z0-9]{26}
|
||||
* @param string $session_data Serialized session data
|
||||
* @return boolean Returns false if parameters are missing, true otherwise
|
||||
*/
|
||||
public function write($session_id, $session_data)
|
||||
{
|
||||
if (!$session_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$session_data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Cache::set('session:' . $session_id, $session_data, Session::$expire);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
Cache::delete('session:' . $id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function gc($maxlifetime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue