function CacheExampleForm::expireFiles

Same name in other branches
  1. 3.x modules/cache_example/src/Form/CacheExampleForm.php \Drupal\cache_example\Form\CacheExampleForm::expireFiles()

Submit handler that explicitly clears cache_example_files_count from cache.

File

modules/cache_example/src/Form/CacheExampleForm.php, line 217

Class

CacheExampleForm
Form with examples on how to use cache.

Namespace

Drupal\cache_example\Form

Code

public function expireFiles($form, &$form_state) {
    // Clear cached data. This function will delete cached object from cache
    // bin.
    //
    // The first argument is cache id to be deleted. Since we've provided it
    // explicitly, it will be removed whether or not it has an associated
    // expiration time. The second argument (required here) is the cache bin.
    // Using cache_clear_all() explicitly in this way
    // forces removal of the cached item.
    $this->cacheBackend
        ->delete('cache_example_files_count');
    // Display message to the user.
    $this->messenger()
        ->addMessage($this->t('Cached data key "cache_example_files_count" was cleared.'), 'status');
}