aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2020-01-17 03:27:38 -0500
committerThedro Neely <thedroneely@gmail.com>2020-01-17 03:27:38 -0500
commita4b54d7b07f0485ce68ab761dd1e491b2e223db7 (patch)
treef7ee9011870242d18ebfa078ff45d556b67a0fea /bootstrap
parent30e82f83ae991639cc2f10c995bb2d0c8503e401 (diff)
downloadthedroneely.com-a4b54d7b07f0485ce68ab761dd1e491b2e223db7.tar.gz
thedroneely.com-a4b54d7b07f0485ce68ab761dd1e491b2e223db7.tar.bz2
thedroneely.com-a4b54d7b07f0485ce68ab761dd1e491b2e223db7.zip
bootstrap/Helpers: Add simple cache
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/Helpers.php34
1 files changed, 29 insertions, 5 deletions
diff --git a/bootstrap/Helpers.php b/bootstrap/Helpers.php
index e92f3ac..575057a 100644
--- a/bootstrap/Helpers.php
+++ b/bootstrap/Helpers.php
@@ -24,16 +24,40 @@ function base64(string $path)
function views(string $folder, string $name)
{
- return $_SERVER['DOCUMENT_ROOT'] . '/..' . '/app/views/' . $folder . '/' . $name .'.php';
+ return $_SERVER['DOCUMENT_ROOT'] . '/..' . '/app/views/'
+ . $folder . '/' . $name .'.php';
}
-function fetch(string $path, string $field)
+function cache(string $filename, string $data)
{
+ file_put_contents(
+ $_SERVER['DOCUMENT_ROOT'] . '/..' . '/app/storage/cache/'
+ . base64_encode($filename), $data
+ );
+}
+
+function fetch(string $uri, string $field)
+{
+ if (file_exists(
+ $_SERVER['DOCUMENT_ROOT'] . '/..'
+ . '/app/storage/cache/' . base64_encode($uri . $field)
+ )
+ ) {
+ echo file_get_contents(
+ $_SERVER['DOCUMENT_ROOT'] . '/..'
+ . '/app/storage/cache/' . base64_encode($uri . $field)
+ );
+ return;
+ }
+
$config = include $_SERVER['DOCUMENT_ROOT'] . '/..' . '/AppConfig.php';
- $json = file_get_contents(
+
+ $request = file_get_contents(
$_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME']
- . $path . '?token=' . $config['cms']['token']
+ . $uri . '?token=' . $config['cms']['token']
);
- $data = json_decode($json, true);
+
+ $data = json_decode($request, true);
+ cache($uri . $field, $data[$field]);
echo $data[$field];
}