Browse Source

add memory cache for compiled pages

main
ghost 10 months ago
parent
commit
3f2bc0b0da
  1. 3
      composer.json
  2. 10
      example/config.json
  3. 36
      src/server.php

3
composer.json

@ -6,7 +6,8 @@
"type": "project", "type": "project",
"require": { "require": {
"yggverse/titan-ii": "^1.0", "yggverse/titan-ii": "^1.0",
"yggverse/gemini": "dev-main" "yggverse/gemini": "dev-main",
"yggverse/cache": "^0.4.0"
}, },
"license": "MIT", "license": "MIT",
"autoload": { "autoload": {

10
example/config.json

@ -7,6 +7,16 @@
"port":1965 "port":1965
} }
}, },
"memcached":
{
"server":
{
"host":"127.0.0.1",
"port":11211,
"timeout":3600,
"namespace":""
}
},
"dokuwiki": "dokuwiki":
{ {
"uri": "uri":

36
src/server.php

@ -60,6 +60,14 @@ $config = json_decode(
) )
); );
// Init memory
$memory = new \Yggverse\Cache\Memory(
$config->memcached->server->host,
$config->memcached->server->port,
$config->memcached->server->namespace,
$config->memcached->server->timeout
);
// Init filesystem // Init filesystem
$filesystem = new \Yggverse\Gemini\Dokuwiki\Filesystem( $filesystem = new \Yggverse\Gemini\Dokuwiki\Filesystem(
sprintf( sprintf(
@ -82,6 +90,7 @@ $server->setHandler(
function (\Yggverse\TitanII\Request $request): \Yggverse\TitanII\Response function (\Yggverse\TitanII\Request $request): \Yggverse\TitanII\Response
{ {
global $config; global $config;
global $memory;
global $filesystem; global $filesystem;
$response = new \Yggverse\TitanII\Response(); $response = new \Yggverse\TitanII\Response();
@ -125,6 +134,16 @@ $server->setHandler(
{ {
if ($path = $filesystem->getPagePathByUri($matches[1])) if ($path = $filesystem->getPagePathByUri($matches[1]))
{ {
// Check for cached results
if ($content = $memory->get($path))
{
$response->setContent(
$content
);
return $response;
}
// Init reader // Init reader
$reader = new \Yggverse\Gemini\Dokuwiki\Reader(); $reader = new \Yggverse\Gemini\Dokuwiki\Reader();
@ -192,12 +211,21 @@ $server->setHandler(
// Append about info // Append about info
$lines[] = $config->string->about; $lines[] = $config->string->about;
// Response // Merge lines
$response->setContent( $content = implode(
implode(
PHP_EOL, PHP_EOL,
$lines $lines
) );
// Cache results
$memory->set(
$path,
$content
);
// Response
$response->setContent(
$content
); );
return $response; return $response;

Loading…
Cancel
Save