From 1df95d7a6e2be89dcfd1c3b17e2ee43e8e5601d1 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Sat, 28 Oct 2023 02:36:20 +0200 Subject: [PATCH] set ttl for files as a constant --- index.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index db93875..c019de9 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,8 @@ require_once "g-sheet-sync.php"; +const TTL = 5 * 60; // time to live for the files in seconds + // credentials.json is the key file we downloaded while setting up our Google Sheets API $credentialsPath = "credentials.json"; // the spreadsheet id (can be found in the url of the doc) @@ -53,7 +55,7 @@ switch ($_SERVER['REQUEST_METHOD']) { } -# TODO: if get: save the json and serve always the same for 5 minutes or something like that +# TODO: if get: save the json and serve always the same for TTL or something like that # use a sha or md5 on the input to return the same output as requested. // $filepath = "test.json"; @@ -72,8 +74,8 @@ function fileExpired(string $filename): bool // if file does not exist counts as expired if (!$filetime) return true; - // if file older than 5 minutes IS expired - if ($filetime < time() - 300) return true; + // if file older than TTL minutes IS expired + if ($filetime < time() - TTL) return true; // else file is NOT expired return false; -- 2.30.2