API client for Kitsu.io, with optional Anime collection, and optional Anilist syncing.
anime
manga
kitsu
anilist
single-user

CachePrime.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php declare(strict_types=1);
  2. /**
  3. * Hummingbird Anime List Client
  4. *
  5. * An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
  6. *
  7. * PHP version 7
  8. *
  9. * @package HummingbirdAnimeClient
  10. * @author Timothy J. Warren <tim@timshomepage.net>
  11. * @copyright 2015 - 2018 Timothy J. Warren
  12. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  13. * @version 4.0
  14. * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
  15. */
  16. namespace Aviat\AnimeClient\Command;
  17. /**
  18. * Clears the API Cache
  19. */
  20. final class CachePrime extends BaseCommand {
  21. /**
  22. * Clear, then prime the API cache
  23. *
  24. * @param array $args
  25. * @param array $options
  26. * @throws \Aviat\Ion\Di\ContainerException
  27. * @throws \Aviat\Ion\Di\NotFoundException
  28. * @return void
  29. */
  30. public function execute(array $args, array $options = []): void
  31. {
  32. $this->setContainer($this->setupContainer());
  33. $cache = $this->container->get('cache');
  34. // Save the user id, if it exists, for priming the cache
  35. $userIdItem = $cache->getItem('kitsu-auth-token');
  36. $userId = $userIdItem->isHit() ? $userIdItem->get() : null;
  37. $cache->clear();
  38. $this->echoBox('Cache cleared, re-priming...');
  39. if ($userId !== NULL)
  40. {
  41. $userIdItem = $cache->getItem('kitsu-auth-token');
  42. $userIdItem->set($userId);
  43. $userIdItem->save();
  44. }
  45. // Prime anime list cache
  46. $kitsuModel = $this->container->get('kitsu-model');
  47. $kitsuModel->getFullOrganizedAnimeList();
  48. // Prime manga list cache
  49. $kitsuModel->getFullOrganizedMangaList();
  50. $this->echoBox('API Cache has been primed.');
  51. }
  52. }