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

10
example/config.json

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

36
src/server.php

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

Loading…
Cancel
Save