Add button to clear api cache

This commit is contained in:
Timothy Warren 2016-04-21 11:14:21 -04:00
parent 47b8a83d86
commit 675ccac14d
7 changed files with 63 additions and 0 deletions

View File

@ -142,6 +142,12 @@ return [
// ---------------------------------------------------------------------
// Default / Shared routes
// ---------------------------------------------------------------------
'cache_purge' => [
'path' => '/cache_purge',
'action' => 'clear_cache',
'controller' => AnimeClient::DEFAULT_CONTROLLER_NAMESPACE,
'verb' => 'get',
],
'login' => [
'path' => '/login',
'action' => 'login',

3
app/views/blank.php Normal file
View File

@ -0,0 +1,3 @@
<main>
<h1><?= $title ?></h1>
</main>

View File

@ -30,6 +30,13 @@
[<a href="<?= $urlGenerator->default_url('manga') ?>">Manga List</a>]
<?php endif ?>
</span>
<?php if ($auth->is_authenticated()): ?>
<span class="flex-no-wrap">&nbsp;</span>
<span class="flex-no-wrap small-font">
<button type="button" class="js-clear-cache user-btn">Clear API Cache</button>
</span>
<span class="flex-no-wrap">&nbsp;</span>
<?php endif ?>
<span class="flex-no-wrap small-font">
<?php if ($auth->is_authenticated()): ?>
<a class="bracketed" href="<?= $url->generate('logout') ?>">Logout</a>

View File

@ -165,6 +165,17 @@ h1 a {
color: #fff;
}
.user-btn {
border-color: #12db18;
color: #12db18;
}
.user-btn:hover,
.user-btn:active {
border-color: #db7d12;
background-color: #db7d12;
}
/* -----------------------------------------------------------------------------
CSS loading icon
------------------------------------------------------------------------------*/

View File

@ -100,6 +100,15 @@ a:hover, a:active {
color:#fff;
}
.user-btn {
border-color: var(--edit-link-color);
color: var(--edit-link-color);
}
.user-btn:hover, .user-btn:active {
border-color: var(--edit-link-hover-color);
background-color: var(--edit-link-hover-color);
}
/* -----------------------------------------------------------------------------
CSS loading icon
------------------------------------------------------------------------------*/

View File

@ -20,4 +20,11 @@
}
});
// Clear the api cache
ac.on('.js-clear-cache', 'click', function (event) {
ac.get('/cache_purge', () => {
ac.showMessage('success', `Sucessfully purged api cache`);
});
});
})(AnimeClient);

View File

@ -27,6 +27,12 @@ class Controller {
use \Aviat\Ion\Di\ContainerAware;
/**
* Cache manager
* @var \Aviat\Ion\Cache\CacheInterface
*/
protected $cache;
/**
* The global configuration object
* @var object $config
@ -83,6 +89,7 @@ class Controller {
$this->setContainer($container);
$auraUrlGenerator = $container->get('aura-router')->getGenerator();
$urlGenerator = $container->get('url-generator');
$this->cache = $container->get('cache');
$this->config = $container->get('config');
$this->request = $container->get('request');
$this->response = $container->get('response');
@ -354,6 +361,19 @@ class Controller {
]);
}
/**
* Purges the API cache
*
* @return void
*/
public function clear_cache()
{
$this->cache->purge();
$this->outputHTML('blank', [
'title' => 'Cache cleared'
], NULL, 200);
}
/**
* Add a message box to the page
*