aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2020-06-19 23:12:35 -0400
committerThedro Neely <thedroneely@gmail.com>2020-06-19 23:42:38 -0400
commit24a400e9ba83bcbfe6e65961e73e0d2cd2ee382f (patch)
tree73cd5ed530fb1ee563689b8c7c69eeb1dfa15a72
parent597f7d5bb024f09278df7da86676ae537337785a (diff)
downloadthedroneely.com-24a400e9ba83bcbfe6e65961e73e0d2cd2ee382f.tar.gz
thedroneely.com-24a400e9ba83bcbfe6e65961e73e0d2cd2ee382f.tar.bz2
thedroneely.com-24a400e9ba83bcbfe6e65961e73e0d2cd2ee382f.zip
app/controllers/api: Add cache controller
-rw-r--r--app/Routes.php4
-rw-r--r--app/controllers/api/cache.controller.php7
-rw-r--r--app/controllers/api/thumbnails.controller.php3
-rwxr-xr-xbootstrap/helpers/cache-bust4
4 files changed, 14 insertions, 4 deletions
diff --git a/app/Routes.php b/app/Routes.php
index 05edf2f..3088e75 100644
--- a/app/Routes.php
+++ b/app/Routes.php
@@ -2,7 +2,6 @@
/**
* Public routes
*/
-
$router->get('', '../app/controllers/index.controller.php');
$router->get('contact', '../app/controllers/contact.controller.php');
@@ -25,5 +24,6 @@ $router->post('contact', '../app/controllers/contact.controller.php');
/**
* Api routes
*/
-
$router->post('api/v1/thumbnails', '../app/controllers/api/thumbnails.controller.php');
+
+$router->post('api/v1/cache', '../app/controllers/api/cache.controller.php');
diff --git a/app/controllers/api/cache.controller.php b/app/controllers/api/cache.controller.php
new file mode 100644
index 0000000..2286445
--- /dev/null
+++ b/app/controllers/api/cache.controller.php
@@ -0,0 +1,7 @@
+<?php
+/**
+ * Invalidate cache
+ */
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ echo $cacheBust = shell_exec('../bootstrap/helpers/cache-bust');
+}
diff --git a/app/controllers/api/thumbnails.controller.php b/app/controllers/api/thumbnails.controller.php
index 5741a47..f2657c0 100644
--- a/app/controllers/api/thumbnails.controller.php
+++ b/app/controllers/api/thumbnails.controller.php
@@ -3,6 +3,5 @@
* Update Thumbnails
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $updateTumbnails = shell_exec('../bootstrap/helpers/update-thumbnails');
- echo '<pre>' . $updateTumbnails . '</pre>';
+ echo $updateTumbnails = shell_exec('../bootstrap/helpers/update-thumbnails');
}
diff --git a/bootstrap/helpers/cache-bust b/bootstrap/helpers/cache-bust
new file mode 100755
index 0000000..267b442
--- /dev/null
+++ b/bootstrap/helpers/cache-bust
@@ -0,0 +1,4 @@
+#!/bin/sh -eu
+cachedir=$(dirname "$(pwd)")/app/storage/cache;
+rm -r "${cachedir:?}/"* > /dev/null 2>&1 || { echo "Nothing to invalidate in ${cachedir:?}" && exit; };
+echo "Cache invalidated in ${cachedir:?}";