From 5a7f495a7973e70860705b1594d5432cd1eb40fb Mon Sep 17 00:00:00 2001 From: Attogram Project Date: Wed, 22 Apr 2020 11:26:48 +0200 Subject: [PATCH] cache time from file --- src/Base.php | 8 +++++--- src/Mediawiki.php | 13 ++++++++----- src/Topic.php | 16 +++++++++------- templates/topic.php | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Base.php b/src/Base.php index 816ce23..9187d6b 100644 --- a/src/Base.php +++ b/src/Base.php @@ -21,10 +21,12 @@ class Base { - const VERSION = '0.6.2'; + const VERSION = '0.7.0'; - /** Cache Time, in seconds. 4 days = 345600 seconds */ - const CACHE_TIME = 345600; + /** Cache Time, in seconds. 4 days = 345600, 14 days = 1209600 */ + const CACHE_TIME = 1209600; + + const DATE_FORMAT = 'Y-m-d H:i:s'; /** key strings */ const ABOUT = 'about'; diff --git a/src/Mediawiki.php b/src/Mediawiki.php index 62eb327..03e0939 100644 --- a/src/Mediawiki.php +++ b/src/Mediawiki.php @@ -61,8 +61,10 @@ public function links($query) return $result; // 404 Not Found } - // set title - $result[self::TITLE] = $data[self::PARSE][self::TITLE]; + + + $result['cached'] = time(); // set cache time + $result[self::TITLE] = $data[self::PARSE][self::TITLE]; // set title // set reference links $result[self::REFS] = isset($data[self::PARSE][self::EXTERNALLINKS]) ? $data[self::PARSE][self::EXTERNALLINKS] @@ -93,15 +95,16 @@ public function search($query) return false; } - $results = []; + $result = []; + $result['cached'] = time(); // set cache time foreach ($data[self::QUERY][self::SEARCH] as $topic) { if (!isset($topic[self::TITLE]) || !is_string($topic[self::TITLE])) { continue; } - $results[] = $topic[self::TITLE]; + $result[] = $topic[self::TITLE]; } - return $results; + return $result; } /** diff --git a/src/Topic.php b/src/Topic.php index 71dc752..637b45a 100644 --- a/src/Topic.php +++ b/src/Topic.php @@ -40,7 +40,7 @@ public function get() $this->initFilesystem(); if ($this->setDataFromCache()) { // get topic data from Cache - if (!empty($this->data['error'])) { + if (!empty($this->data['error'])) { // if cache contains error report (404) $this->error404(self::ERROR_NOT_FOUND, $this->topic); return; @@ -108,13 +108,15 @@ private function display() // set Extraction source url $this->template->set('source', $this->source . $this->encodeLink($this->data[self::TITLE])); - - // set Data and Cache age - $filesystemCache = new FilesystemCache(); - $this->template->set('dataAge', $filesystemCache->getAge($this->data[self::TITLE])); - $this->template->set('now', gmdate('Y-m-d H:i:s')); + $this->template->set('now', gmdate(self::DATE_FORMAT)); + + if (!isset($this->data['cached'])) { // if no cache time is set... + $this->data['cached'] = time(); + } + $this->template->set('cached', gmdate(self::DATE_FORMAT, $this->data['cached'])); + $this->template->set( - 'refresh', + 'refresh', // refresh link $this->template->get('home') . 'refresh/' . $this->encodeLink($this->data[self::TITLE]) ); $this->template->set('h1', $this->data[self::TITLE]); diff --git a/templates/topic.php b/templates/topic.php index 934a09f..bc3d9ff 100644 --- a/templates/topic.php +++ b/templates/topic.php @@ -24,7 +24,7 @@ get('draft_count') ?> Drafts, get('user_count') ?> Users -
  • Cached get('dataAge') ?> UTC (refresh)
  • +
  • Cached get('cached') ?> UTC (refresh)
  • Served get('now') ?> UTC
  • Extracted from <get('source') ?>> released under the Creative Commons Attribution-Share-Alike License 3.0