set ttl for files as a constant
authorEduardo <[email protected]>
Sat, 28 Oct 2023 00:36:20 +0000 (02:36 +0200)
committerEduardo <[email protected]>
Sat, 28 Oct 2023 00:36:20 +0000 (02:36 +0200)
index.php

index db93875efa1af9bf9e66aba02eb79df95e6f4bf9..c019de9250bcfc406f5543b4a70b87e8a7a4dc93 100644 (file)
--- 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;