cache_8.inc

  1. 8.0.x commands/core/drupal/cache_8.inc
  2. 7.x commands/core/drupal/cache_8.inc
  3. master commands/core/drupal/cache_8.inc

Engine for the cache commands.

Functions

File

commands/core/drupal/cache_8.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Engine for the cache commands.
  5. */
  6. use Drupal\Core\Cache\Cache;
  7. function _drush_cache_command_get($cid, $bin) {
  8. if (is_null($bin)) {
  9. $bin = _drush_cache_bin_default();
  10. }
  11. return \Drupal::cache($bin)->get($cid);
  12. }
  13. /**
  14. * The default bin.
  15. *
  16. * @return string
  17. */
  18. function _drush_cache_bin_default() {
  19. return 'default';
  20. }
  21. function _drush_cache_command_set($cid, $data, $bin, $expire, $tags) {
  22. if (is_null($bin)) {
  23. $bin = _drush_cache_bin_default();
  24. }
  25. // Convert the "expire" argument to a valid value for Drupal's cache_set().
  26. if ($expire == 'CACHE_TEMPORARY') {
  27. $expire = Cache::TEMPORARY;
  28. }
  29. if (!isset($expire) || $expire == 'CACHE_PERMANENT') {
  30. $expire = Cache::PERMANENT;
  31. }
  32. return \Drupal::cache($bin)->set($cid, $data, $expire, $tags);
  33. }
  34. function _drush_cache_clear_types($include_bootstrapped_types) {
  35. $types = array(
  36. 'drush' => 'drush_cache_clear_drush',
  37. );
  38. if ($include_bootstrapped_types) {
  39. $types += array(
  40. 'theme-registry' => 'drush_cache_clear_theme_registry',
  41. 'menu' => 'drush_cache_clear_menu',
  42. 'css-js' => 'drush_cache_clear_css_js',
  43. 'module-list' => 'drush_get_modules',
  44. 'theme-list' => 'drush_get_themes',
  45. 'render' => 'drush_cache_clear_render',
  46. );
  47. }
  48. return $types;
  49. }
  50. function drush_cache_clear_theme_registry() {
  51. \Drupal::service('theme.registry')->reset();
  52. }
  53. function drush_cache_clear_menu() {
  54. /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
  55. $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
  56. return $menu_link_manager->rebuild();
  57. }
  58. function drush_cache_clear_css_js() {
  59. _drupal_flush_css_js();
  60. drupal_clear_css_cache();
  61. drupal_clear_js_cache();
  62. }
  63. /**
  64. * Clear the cache of the block output.
  65. */
  66. function drush_cache_clear_block() {
  67. // There is no distinct block cache in D8. See https://github.com/drush-ops/drush/issues/1531.
  68. // \Drupal::cache('block')->deleteAll();
  69. }
  70. /**
  71. * Clears the render cache entries.
  72. */
  73. function drush_cache_clear_render() {
  74. Cache::invalidateTags(['rendered']);
  75. }