From 8ece2c2b25445194dad670ce677924fb19057e46 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Sat, 12 Mar 2022 19:28:37 +0100 Subject: [PATCH] Fixed JSON Cache and Cache returning VERIFY_CODE --- app/Cache/JSONCache.php | 16 ++++------------ composer.json | 2 +- composer.lock | 14 +++++++------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/Cache/JSONCache.php b/app/Cache/JSONCache.php index 3930a64..fd7b44a 100644 --- a/app/Cache/JSONCache.php +++ b/app/Cache/JSONCache.php @@ -9,19 +9,14 @@ class JSONCache { $this->cache_path = $_ENV['API_CACHE_JSON']; } } - public function get(string $cache_key): object|false { + public function get(string $cache_key): ?object { $filename = $this->cache_path . '/' . $cache_key . '.json'; if (is_file($filename)) { - $time = time(); $json_string = file_get_contents($filename); $element = json_decode($json_string); - if ($time < $element->expires) { - return $element->data; - } - // Remove file if expired - unlink($filename); + return $element; } - return false; + return null; } public function exists(string $cache_key): bool { @@ -30,9 +25,6 @@ class JSONCache { } public function set(string $cache_key, mixed $data, $timeout = 3600) { - file_put_contents($this->cache_path . '/' . $cache_key . '.json', json_encode([ - 'data' => $data, - 'expires' => time() + $timeout - ])); + file_put_contents($this->cache_path . '/' . $cache_key . '.json', $data); } } diff --git a/composer.json b/composer.json index 74a30da..f3af9e9 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "vlucas/phpdotenv": "^5.4", "bramus/router": "^1.6", "mibe/feedwriter": "^1.1", - "pablouser1/tikscraper": "v1.2.7.4" + "pablouser1/tikscraper": "^1.2" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index ed0b97b..cf7f18e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4cef118e8b6abab34ab1af853d20598b", + "content-hash": "cadd5f76328389373f21a069e55f8aae", "packages": [ { "name": "bramus/router", @@ -306,16 +306,16 @@ }, { "name": "pablouser1/tikscraper", - "version": "v1.2.7.4", + "version": "v1.2.7.6", "source": { "type": "git", "url": "https://github.com/pablouser1/TikScraperPHP.git", - "reference": "f42df2e947cfe9afc31a46737a48e720f161ef1c" + "reference": "e7e682726e76541dc47d14dd259a29b3c0364790" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/f42df2e947cfe9afc31a46737a48e720f161ef1c", - "reference": "f42df2e947cfe9afc31a46737a48e720f161ef1c", + "url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/e7e682726e76541dc47d14dd259a29b3c0364790", + "reference": "e7e682726e76541dc47d14dd259a29b3c0364790", "shasum": "" }, "require": { @@ -339,9 +339,9 @@ "description": "Get data from TikTok API", "support": { "issues": "https://github.com/pablouser1/TikScraperPHP/issues", - "source": "https://github.com/pablouser1/TikScraperPHP/tree/v1.2.7.4" + "source": "https://github.com/pablouser1/TikScraperPHP/tree/v1.2.7.6" }, - "time": "2022-03-11T21:42:09+00:00" + "time": "2022-03-12T18:27:40+00:00" }, { "name": "phpoption/phpoption",