Fixed JSON Cache and Cache returning VERIFY_CODE
This commit is contained in:
parent
7ba324c935
commit
8ece2c2b25
|
@ -9,19 +9,14 @@ class JSONCache {
|
||||||
$this->cache_path = $_ENV['API_CACHE_JSON'];
|
$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';
|
$filename = $this->cache_path . '/' . $cache_key . '.json';
|
||||||
if (is_file($filename)) {
|
if (is_file($filename)) {
|
||||||
$time = time();
|
|
||||||
$json_string = file_get_contents($filename);
|
$json_string = file_get_contents($filename);
|
||||||
$element = json_decode($json_string);
|
$element = json_decode($json_string);
|
||||||
if ($time < $element->expires) {
|
return $element;
|
||||||
return $element->data;
|
|
||||||
}
|
}
|
||||||
// Remove file if expired
|
return null;
|
||||||
unlink($filename);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exists(string $cache_key): bool {
|
public function exists(string $cache_key): bool {
|
||||||
|
@ -30,9 +25,6 @@ class JSONCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set(string $cache_key, mixed $data, $timeout = 3600) {
|
public function set(string $cache_key, mixed $data, $timeout = 3600) {
|
||||||
file_put_contents($this->cache_path . '/' . $cache_key . '.json', json_encode([
|
file_put_contents($this->cache_path . '/' . $cache_key . '.json', $data);
|
||||||
'data' => $data,
|
|
||||||
'expires' => time() + $timeout
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
"vlucas/phpdotenv": "^5.4",
|
"vlucas/phpdotenv": "^5.4",
|
||||||
"bramus/router": "^1.6",
|
"bramus/router": "^1.6",
|
||||||
"mibe/feedwriter": "^1.1",
|
"mibe/feedwriter": "^1.1",
|
||||||
"pablouser1/tikscraper": "v1.2.7.4"
|
"pablouser1/tikscraper": "^1.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
14
composer.lock
generated
14
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "4cef118e8b6abab34ab1af853d20598b",
|
"content-hash": "cadd5f76328389373f21a069e55f8aae",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "bramus/router",
|
"name": "bramus/router",
|
||||||
|
@ -306,16 +306,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "pablouser1/tikscraper",
|
"name": "pablouser1/tikscraper",
|
||||||
"version": "v1.2.7.4",
|
"version": "v1.2.7.6",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/pablouser1/TikScraperPHP.git",
|
"url": "https://github.com/pablouser1/TikScraperPHP.git",
|
||||||
"reference": "f42df2e947cfe9afc31a46737a48e720f161ef1c"
|
"reference": "e7e682726e76541dc47d14dd259a29b3c0364790"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/f42df2e947cfe9afc31a46737a48e720f161ef1c",
|
"url": "https://api.github.com/repos/pablouser1/TikScraperPHP/zipball/e7e682726e76541dc47d14dd259a29b3c0364790",
|
||||||
"reference": "f42df2e947cfe9afc31a46737a48e720f161ef1c",
|
"reference": "e7e682726e76541dc47d14dd259a29b3c0364790",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -339,9 +339,9 @@
|
||||||
"description": "Get data from TikTok API",
|
"description": "Get data from TikTok API",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/pablouser1/TikScraperPHP/issues",
|
"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",
|
"name": "phpoption/phpoption",
|
||||||
|
|
Loading…
Reference in a new issue