diff --git a/src/api/statistics.php b/src/api/statistics.php index 03585a76..d6775495 100644 --- a/src/api/statistics.php +++ b/src/api/statistics.php @@ -30,7 +30,8 @@ switch ($_SERVER['REQUEST_METHOD']) { foreach ($tables as $table) { $count = new Cache\Query( 'SELECT COUNT(`id`) AS "count" - FROM `' . $table . '`;' + FROM `' . $table . '`;', + Duration::DAY ); $response['data'][$table] = $count->get(); diff --git a/src/classes/cache/blog.php b/src/classes/cache/blog.php index 3fc8506b..72ae56e5 100644 --- a/src/classes/cache/blog.php +++ b/src/classes/cache/blog.php @@ -21,10 +21,9 @@ class Blog extends Cache */ public function __construct($url) { - parent::__construct($url); + parent::__construct($url, \wishthis\Duration::DAY); $this->directory .= '/blog'; - $this->maxAge = 86400; // 24 hours } public function get(): \stdClass|array diff --git a/src/classes/cache/cache.php b/src/classes/cache/cache.php index 7bea6432..ef1fcb96 100644 --- a/src/classes/cache/cache.php +++ b/src/classes/cache/cache.php @@ -8,12 +8,16 @@ namespace wishthis\Cache; class Cache { + /** + * Private + */ + private int $maxAge; + /** * Protected */ protected string $url; protected string $directory = ROOT . '/src/cache'; - protected int $maxAge = 2592000; // 30 days protected function getAge(): int { @@ -50,9 +54,10 @@ class Cache /** * Public */ - public function __construct($url) + public function __construct(string $url, int $maxAge = \wishthis\Duration::YEAR) { - $this->url = trim($url); + $this->url = trim($url); + $this->maxAge = $maxAge; } public function exists(): bool diff --git a/src/classes/cache/embed.php b/src/classes/cache/embed.php index 423b3f47..a9d16027 100644 --- a/src/classes/cache/embed.php +++ b/src/classes/cache/embed.php @@ -25,7 +25,7 @@ class Embed extends Cache */ public function __construct($url) { - parent::__construct($url); + parent::__construct($url, \wishthis\Duration::MONTH); $this->directory .= '/embed'; } diff --git a/src/classes/cache/query.php b/src/classes/cache/query.php index 0178a371..5f50fa18 100644 --- a/src/classes/cache/query.php +++ b/src/classes/cache/query.php @@ -16,11 +16,11 @@ class Query extends Cache /** * Public */ - public function __construct($url) + public function __construct(string $url, int $maxAge = \wishthis\Duration::YEAR) { global $database; - parent::__construct($url); + parent::__construct($url, $maxAge); $this->directory .= '/query'; $this->database = $database; diff --git a/src/classes/duration.php b/src/classes/duration.php new file mode 100644 index 00000000..9b2af1ea --- /dev/null +++ b/src/classes/duration.php @@ -0,0 +1,13 @@ +