How to clear cache programmatically in Drupal 8?

Pupil picture Pupil · Apr 25, 2017 · Viewed 14.4k times · Source

I am working on a Drupal 8 site. This site was working. I recently moved to another machine.

It is showing errors like:

Recoverable fatal error: Argument 1 passed to 

Drupal\Component\DependencyInjection\Container::__construct() must be of

 the type array, boolean given, called in [DRUPAL-

PATH]/core/lib/Drupal/Core/DrupalKernel.php on line 883 and defined in 

[DRUPAL-PATH]/core/lib/Drupal/Component/DependencyInjection/Container.php

 on line 119 #0 [DRUPAL-PATH]/core/includes/bootstrap.inc(550): 

_drupal_error_handler_real(4096, 'Argument 1 pass...', 

'/Applications/M...', 119, Array)

I need to clear cache programmatically.

Answer

sreekanth kuriyala picture sreekanth kuriyala · Apr 27, 2017

Try below.

cache_clear_all() // For Drupal-7

drupal_flush_all_caches() // For Drupal-8