mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
cache connection data on browser close only
This commit is contained in:
parent
1cb3db9923
commit
48c682459d
6 changed files with 44 additions and 66 deletions
|
|
@ -244,27 +244,6 @@ abstract class Connection implements \Yggverse\Yoda\Interface\Model\Connection
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cache(
|
|
||||||
string $request
|
|
||||||
): void
|
|
||||||
{
|
|
||||||
$pid = pcntl_fork(); // not wait
|
|
||||||
|
|
||||||
if ($pid === 0)
|
|
||||||
{
|
|
||||||
$this->_database->renewCache(
|
|
||||||
$request,
|
|
||||||
$this->getMime(),
|
|
||||||
$this->getTitle(),
|
|
||||||
$this->getSubtitle(),
|
|
||||||
$this->getTooltip(),
|
|
||||||
$this->getData()
|
|
||||||
);
|
|
||||||
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reset(): void
|
public function reset(): void
|
||||||
{
|
{
|
||||||
$this->_pool->reset();
|
$this->_pool->reset();
|
||||||
|
|
|
||||||
|
|
@ -84,18 +84,33 @@ class Browser
|
||||||
'destroy',
|
'destroy',
|
||||||
function()
|
function()
|
||||||
{
|
{
|
||||||
// Save session
|
// Save session data
|
||||||
$pid = pcntl_fork();
|
$pid = pcntl_fork();
|
||||||
|
|
||||||
if ($pid === 0)
|
if ($pid === 0)
|
||||||
{
|
{
|
||||||
|
// Reset previous records
|
||||||
$this->database->cleanSession();
|
$this->database->cleanSession();
|
||||||
|
|
||||||
foreach ($this->container->tab->pages as $page)
|
foreach ($this->container->tab->pages as $page)
|
||||||
{
|
{
|
||||||
|
// Save page session data
|
||||||
$this->database->addSession(
|
$this->database->addSession(
|
||||||
$page->navbar->request->getValue()
|
$page->navbar->request->getValue()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Cache connection pool data
|
||||||
|
if ($page->connection)
|
||||||
|
{
|
||||||
|
$this->database->renewCache(
|
||||||
|
$page->navbar->request->getValue(),
|
||||||
|
$page->connection->getMime(),
|
||||||
|
$page->connection->getTitle(),
|
||||||
|
$page->connection->getSubtitle(),
|
||||||
|
$page->connection->getTooltip(),
|
||||||
|
$page->connection->getData()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ class Page
|
||||||
public Page\Content $content;
|
public Page\Content $content;
|
||||||
public Page\Response $response;
|
public Page\Response $response;
|
||||||
|
|
||||||
|
public ?Connection $connection = null;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Container $container
|
Container $container
|
||||||
) {
|
) {
|
||||||
|
|
@ -165,13 +167,20 @@ class Page
|
||||||
// Hide response form
|
// Hide response form
|
||||||
$this->response->hide();
|
$this->response->hide();
|
||||||
|
|
||||||
|
// Drop previous connection
|
||||||
|
if ($this->connection)
|
||||||
|
{
|
||||||
|
// Free memory
|
||||||
|
$this->connection->close();
|
||||||
|
}
|
||||||
|
|
||||||
// Update content using multi-protocol driver
|
// Update content using multi-protocol driver
|
||||||
$connection = new Connection(
|
$this->connection = new Connection(
|
||||||
$this->container->browser->database
|
$this->container->browser->database
|
||||||
);
|
);
|
||||||
|
|
||||||
// Async request
|
// Async request
|
||||||
$connection->request(
|
$this->connection->request(
|
||||||
$this->navbar->request->getValue(),
|
$this->navbar->request->getValue(),
|
||||||
$timeout
|
$timeout
|
||||||
);
|
);
|
||||||
|
|
@ -182,10 +191,10 @@ class Page
|
||||||
// Listen response
|
// Listen response
|
||||||
Gtk::timeout_add(
|
Gtk::timeout_add(
|
||||||
$refresh,
|
$refresh,
|
||||||
function() use ($connection, $expire, $history)
|
function() use ($expire, $history)
|
||||||
{
|
{
|
||||||
// Redirect requested
|
// Redirect requested
|
||||||
if ($location = $connection->getRedirect())
|
if ($location = $this->connection->getRedirect())
|
||||||
{
|
{
|
||||||
// Follow
|
// Follow
|
||||||
$this->open(
|
$this->open(
|
||||||
|
|
@ -195,20 +204,17 @@ class Page
|
||||||
// Hide progressbar
|
// Hide progressbar
|
||||||
$this->progressbar->hide();
|
$this->progressbar->hide();
|
||||||
|
|
||||||
// Free shared memory pool
|
|
||||||
$connection->close();
|
|
||||||
|
|
||||||
return false; // stop
|
return false; // stop
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response form requested
|
// Response form requested
|
||||||
if ($request = $connection->getRequest())
|
if ($request = $this->connection->getRequest())
|
||||||
{
|
{
|
||||||
// Update title
|
// Update title
|
||||||
$this->title->set(
|
$this->title->set(
|
||||||
$connection->getTitle(),
|
$this->connection->getTitle(),
|
||||||
$connection->getSubtitle(),
|
$this->connection->getSubtitle(),
|
||||||
$connection->getTooltip()
|
$this->connection->getTooltip()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Refresh header by new title if current page is active
|
// Refresh header by new title if current page is active
|
||||||
|
|
@ -229,20 +235,17 @@ class Page
|
||||||
// Hide progressbar
|
// Hide progressbar
|
||||||
$this->progressbar->hide();
|
$this->progressbar->hide();
|
||||||
|
|
||||||
// Free shared memory pool
|
|
||||||
$connection->close();
|
|
||||||
|
|
||||||
return false; // stop
|
return false; // stop
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop event loop on request completed
|
// Stop event loop on request completed
|
||||||
if ($connection->isCompleted())
|
if ($this->connection->isCompleted())
|
||||||
{
|
{
|
||||||
// Update title
|
// Update title
|
||||||
$this->title->set(
|
$this->title->set(
|
||||||
$connection->getTitle(),
|
$this->connection->getTitle(),
|
||||||
$connection->getSubtitle(),
|
$this->connection->getSubtitle(),
|
||||||
$connection->getTooltip()
|
$this->connection->getTooltip()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Refresh header by new title if current page is active
|
// Refresh header by new title if current page is active
|
||||||
|
|
@ -256,16 +259,13 @@ class Page
|
||||||
|
|
||||||
// Update content
|
// Update content
|
||||||
$this->content->set(
|
$this->content->set(
|
||||||
$connection->getMime(),
|
$this->connection->getMime(),
|
||||||
$connection->getData()
|
$this->connection->getData()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hide progressbar
|
// Hide progressbar
|
||||||
$this->progressbar->hide();
|
$this->progressbar->hide();
|
||||||
|
|
||||||
// Free shared memory pool
|
|
||||||
$connection->close();
|
|
||||||
|
|
||||||
// Update history
|
// Update history
|
||||||
if ($history)
|
if ($history)
|
||||||
{
|
{
|
||||||
|
|
@ -317,9 +317,6 @@ class Page
|
||||||
// Hide progressbar
|
// Hide progressbar
|
||||||
$this->progressbar->hide();
|
$this->progressbar->hide();
|
||||||
|
|
||||||
// Free shared memory pool
|
|
||||||
$connection->close();
|
|
||||||
|
|
||||||
// Stop
|
// Stop
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,10 +80,6 @@ interface Connection
|
||||||
string $request
|
string $request
|
||||||
): ?object;
|
): ?object;
|
||||||
|
|
||||||
public function cache(
|
|
||||||
string $request
|
|
||||||
): void;
|
|
||||||
|
|
||||||
public function reset(): void;
|
public function reset(): void;
|
||||||
|
|
||||||
public function close(): void;
|
public function close(): void;
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Yggverse\Yoda\Model\Connection;
|
namespace Yggverse\Yoda\Model\Connection;
|
||||||
|
|
||||||
use \Yggverse\Gemini\Client\Request;
|
|
||||||
use \Yggverse\Gemini\Client\Response;
|
|
||||||
use \Yggverse\Net\Address;
|
|
||||||
|
|
||||||
use \Yggverse\Yoda\Model\Connection;
|
use \Yggverse\Yoda\Model\Connection;
|
||||||
use \Yggverse\Yoda\Model\Filesystem;
|
use \Yggverse\Yoda\Model\Filesystem;
|
||||||
|
|
||||||
|
use \Yggverse\Gemini\Client\Request;
|
||||||
|
use \Yggverse\Gemini\Client\Response;
|
||||||
|
|
||||||
|
use \Yggverse\Net\Address;
|
||||||
|
|
||||||
class Gemini
|
class Gemini
|
||||||
{
|
{
|
||||||
private Connection $_connection;
|
private Connection $_connection;
|
||||||
|
|
@ -114,11 +115,6 @@ class Gemini
|
||||||
$response->getBody()
|
$response->getBody()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Cache
|
|
||||||
$this->_connection->cache(
|
|
||||||
$address->get()
|
|
||||||
);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 31: // redirect
|
case 31: // redirect
|
||||||
|
|
|
||||||
|
|
@ -72,11 +72,6 @@ class Nex
|
||||||
$this->_connection->setData(
|
$this->_connection->setData(
|
||||||
$response
|
$response
|
||||||
);
|
);
|
||||||
|
|
||||||
// Cache
|
|
||||||
$this->_connection->cache(
|
|
||||||
$address->get()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try cache
|
// Try cache
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue