function cache_example_form_cache_clearing in Examples for Developers 7
Submit handler to demonstrate the various uses of cache_clear_all().
Related topics
1 string reference to 'cache_example_form_cache_clearing'
- cache_example_page_form in cache_example/
cache_example.module - Main page for cache_example.
File
- cache_example/
cache_example.module, line 219 - Outlines how a module can use the Cache API.
Code
function cache_example_form_cache_clearing($form, &$form_state) {
switch ($form_state['values']['cache_clear_type']) {
case 'expire':
// Here we'll remove all cache keys in the 'cache' bin that have expired.
cache_clear_all(NULL, 'cache');
drupal_set_message(t('cache_clear_all(NULL, "cache") was called, removing any expired cache items.'));
break;
case 'remove_all':
// This removes all keys in a bin using a super-wildcard. This
// has nothing to do with expiration. It's just brute-force removal.
cache_clear_all('*', 'cache', TRUE);
drupal_set_message(t('ALL entries in the "cache" bin were removed with cache_clear_all("*", "cache", TRUE).'));
break;
case 'remove_wildcard':
// We can also explicitly remove all cache items whose cid begins with
// 'cache_example' by using a wildcard. This again is brute-force
// removal, not expiration.
cache_clear_all('cache_example', 'cache', TRUE);
drupal_set_message(t('Cache entries whose cid began with "cache_example" in the "cache" bin were removed with cache_clear_all("cache_example", "cache", TRUE).'));
break;
}
}