diff --git a/src/Abstract/Model/Connection.php b/src/Abstract/Model/Connection.php index 7a9e7180..a5d52290 100644 --- a/src/Abstract/Model/Connection.php +++ b/src/Abstract/Model/Connection.php @@ -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 { $this->_pool->reset(); diff --git a/src/Entity/Browser.php b/src/Entity/Browser.php index 8905ab6e..df87465e 100644 --- a/src/Entity/Browser.php +++ b/src/Entity/Browser.php @@ -84,18 +84,33 @@ class Browser 'destroy', function() { - // Save session + // Save session data $pid = pcntl_fork(); if ($pid === 0) { + // Reset previous records $this->database->cleanSession(); foreach ($this->container->tab->pages as $page) { + // Save page session data $this->database->addSession( $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; diff --git a/src/Entity/Browser/Container/Page.php b/src/Entity/Browser/Container/Page.php index cf6b1d7d..6f2916a4 100644 --- a/src/Entity/Browser/Container/Page.php +++ b/src/Entity/Browser/Container/Page.php @@ -29,6 +29,8 @@ class Page public Page\Content $content; public Page\Response $response; + public ?Connection $connection = null; + public function __construct( Container $container ) { @@ -165,13 +167,20 @@ class Page // Hide response form $this->response->hide(); + // Drop previous connection + if ($this->connection) + { + // Free memory + $this->connection->close(); + } + // Update content using multi-protocol driver - $connection = new Connection( + $this->connection = new Connection( $this->container->browser->database ); // Async request - $connection->request( + $this->connection->request( $this->navbar->request->getValue(), $timeout ); @@ -182,10 +191,10 @@ class Page // Listen response Gtk::timeout_add( $refresh, - function() use ($connection, $expire, $history) + function() use ($expire, $history) { // Redirect requested - if ($location = $connection->getRedirect()) + if ($location = $this->connection->getRedirect()) { // Follow $this->open( @@ -195,20 +204,17 @@ class Page // Hide progressbar $this->progressbar->hide(); - // Free shared memory pool - $connection->close(); - return false; // stop } // Response form requested - if ($request = $connection->getRequest()) + if ($request = $this->connection->getRequest()) { // Update title $this->title->set( - $connection->getTitle(), - $connection->getSubtitle(), - $connection->getTooltip() + $this->connection->getTitle(), + $this->connection->getSubtitle(), + $this->connection->getTooltip() ); // Refresh header by new title if current page is active @@ -229,20 +235,17 @@ class Page // Hide progressbar $this->progressbar->hide(); - // Free shared memory pool - $connection->close(); - return false; // stop } // Stop event loop on request completed - if ($connection->isCompleted()) + if ($this->connection->isCompleted()) { // Update title $this->title->set( - $connection->getTitle(), - $connection->getSubtitle(), - $connection->getTooltip() + $this->connection->getTitle(), + $this->connection->getSubtitle(), + $this->connection->getTooltip() ); // Refresh header by new title if current page is active @@ -256,16 +259,13 @@ class Page // Update content $this->content->set( - $connection->getMime(), - $connection->getData() + $this->connection->getMime(), + $this->connection->getData() ); // Hide progressbar $this->progressbar->hide(); - // Free shared memory pool - $connection->close(); - // Update history if ($history) { @@ -317,9 +317,6 @@ class Page // Hide progressbar $this->progressbar->hide(); - // Free shared memory pool - $connection->close(); - // Stop return false; } diff --git a/src/Interface/Model/Connection.php b/src/Interface/Model/Connection.php index a6857909..08a01313 100644 --- a/src/Interface/Model/Connection.php +++ b/src/Interface/Model/Connection.php @@ -80,10 +80,6 @@ interface Connection string $request ): ?object; - public function cache( - string $request - ): void; - public function reset(): void; public function close(): void; diff --git a/src/Model/Connection/Gemini.php b/src/Model/Connection/Gemini.php index 295bc6e9..bf4a5c8c 100644 --- a/src/Model/Connection/Gemini.php +++ b/src/Model/Connection/Gemini.php @@ -4,12 +4,13 @@ declare(strict_types=1); namespace Yggverse\Yoda\Model\Connection; +use \Yggverse\Yoda\Model\Connection; +use \Yggverse\Yoda\Model\Filesystem; + use \Yggverse\Gemini\Client\Request; use \Yggverse\Gemini\Client\Response; -use \Yggverse\Net\Address; -use \Yggverse\Yoda\Model\Connection; -use \Yggverse\Yoda\Model\Filesystem; +use \Yggverse\Net\Address; class Gemini { @@ -114,11 +115,6 @@ class Gemini $response->getBody() ); - // Cache - $this->_connection->cache( - $address->get() - ); - break; case 31: // redirect diff --git a/src/Model/Connection/Nex.php b/src/Model/Connection/Nex.php index 8d8e7a4c..ed6add3a 100644 --- a/src/Model/Connection/Nex.php +++ b/src/Model/Connection/Nex.php @@ -72,11 +72,6 @@ class Nex $this->_connection->setData( $response ); - - // Cache - $this->_connection->cache( - $address->get() - ); } // Try cache