Version 5.1 - All the GraphQL #32
@ -91,15 +91,10 @@ class Anime extends BaseController {
|
||||
'completed' => AnimeWatchingStatus::COMPLETED
|
||||
];
|
||||
|
||||
if (array_key_exists($type, $type_title_map))
|
||||
{
|
||||
$title = $this->config->get('whose_list') .
|
||||
"'s Anime List · {$type_title_map[$type]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = '';
|
||||
}
|
||||
$title = (array_key_exists($type, $type_title_map))
|
||||
? $this->config->get('whose_list') .
|
||||
"'s Anime List · {$type_title_map[$type]}"
|
||||
: '';
|
||||
|
||||
$view_map = [
|
||||
'' => 'cover',
|
||||
@ -110,10 +105,6 @@ class Anime extends BaseController {
|
||||
? $this->cache->get($this->model, 'get_list', ['status' => $model_map[$type]])
|
||||
: $this->cache->get($this->model, 'get_all_lists', []);
|
||||
|
||||
/*$data = ($type != 'all')
|
||||
? $this->model->get_list($model_map[$type])
|
||||
: $this->model->get_all_lists();*/
|
||||
|
||||
$this->outputHTML('anime/' . $view_map[$view], [
|
||||
'title' => $title,
|
||||
'sections' => $data
|
||||
@ -166,6 +157,7 @@ class Anime extends BaseController {
|
||||
if ($result['statusCode'] == 201)
|
||||
{
|
||||
$this->set_flash_message('Added new anime to list', 'success');
|
||||
$this->cache->purge();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -245,6 +237,7 @@ class Anime extends BaseController {
|
||||
: "{$result['anime']['title']}";
|
||||
|
||||
$this->set_flash_message("Successfully updated {$title}.", 'success');
|
||||
$this->cache->purge();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -260,6 +253,7 @@ class Anime extends BaseController {
|
||||
public function update()
|
||||
{
|
||||
$response = $this->model->update($this->request->getParsedBody());
|
||||
$this->cache->purge();
|
||||
$this->outputJSON($response['body'], $response['statusCode']);
|
||||
}
|
||||
|
||||
@ -269,6 +263,7 @@ class Anime extends BaseController {
|
||||
public function delete()
|
||||
{
|
||||
$response = $this->model->update($this->request->getParsedBody());
|
||||
$this->cache->purge();
|
||||
$this->outputJSON($response['body'], $response['statusCode']);
|
||||
}
|
||||
|
||||
|
@ -40,5 +40,12 @@ interface CacheDriverInterface {
|
||||
* @return CacheDriverInterface
|
||||
*/
|
||||
public function invalidate($key);
|
||||
|
||||
/**
|
||||
* Clear the contents of the cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function invalidateAll();
|
||||
}
|
||||
// End of CacheDriverInterface.php
|
@ -27,5 +27,22 @@ interface CacheInterface {
|
||||
* @return mixed - the cached or fresh data
|
||||
*/
|
||||
public function get($object, $method, array $args=[]);
|
||||
|
||||
/**
|
||||
* Retreive a fresh value, and update the cache
|
||||
*
|
||||
* @param object $object - object to retrieve fresh value from
|
||||
* @param string $method - method name to call
|
||||
* @param [array] $args - the arguments to pass to the retrieval method
|
||||
* @return mixed - the fresh data
|
||||
*/
|
||||
public function getFresh($object, $method, array $args=[]);
|
||||
|
||||
/**
|
||||
* Clear the entire cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge();
|
||||
}
|
||||
// End of CacheInterface.php
|
@ -77,6 +77,16 @@ class CacheManager implements CacheInterface {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the entire cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function purge()
|
||||
{
|
||||
$this->driver->invalidateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a hash as a cache key from the current method call
|
||||
*
|
||||
@ -85,7 +95,7 @@ class CacheManager implements CacheInterface {
|
||||
* @param array $args
|
||||
* @return string
|
||||
*/
|
||||
public function generateHashForMethod($object, $method, array $args)
|
||||
protected function generateHashForMethod($object, $method, array $args)
|
||||
{
|
||||
$classname = get_class($object);
|
||||
$keyObj = [
|
||||
|
@ -106,5 +106,15 @@ class SQLDriver extends DB implements \Aviat\Ion\Cache\CacheDriverInterface {
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the contents of the cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function invalidateAll()
|
||||
{
|
||||
$this->db->truncate('cache');
|
||||
}
|
||||
}
|
||||
// End of SQLDriver.php
|
Loading…
Reference in New Issue
Block a user