Skip to main content
removed a useless sentence
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

To delete from the cache the cache item set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set(), for example.

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the deleted cache item is the one whose cache ID of the deleted item is variables, which is contained in the cache_bootstrap cache bin.

As side note, cache_clear_all() could be also used to delete all the cache items whose IDs start with the string passed as first argument. For example, cache_clear_all('mymodule_', 'cache', TRUE) would delete the cache items havingwhose cache IDs are mymodule_cached_data or mymodule_long_calculus_result as, for example. It won't delete a cache item whose ID is user_cached_data, for example.

To delete from the cache the cache item set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set().

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the deleted cache item is the one whose cache ID is variables, contained in the cache_bootstrap cache bin.

As side note, cache_clear_all() could be also used to delete all the cache items whose IDs start with the string passed as first argument. For example, cache_clear_all('mymodule_', 'cache', TRUE) would delete the cache items having mymodule_cached_data or mymodule_long_calculus_result as cache ID.

Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set(), for example.

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the cache ID of the deleted item is variables, which is contained in the cache_bootstrap cache bin.

As side note, cache_clear_all() could be also used to delete all the cache items whose IDs start with the string passed as first argument. For example, cache_clear_all('mymodule_', 'cache', TRUE) would delete the cache items whose cache IDs are mymodule_cached_data or mymodule_long_calculus_result, for example. It won't delete a cache item whose ID is user_cached_data, for example.

added a note about deleting cache items knowing the first part of the cache ID
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

To delete from the cache the cache item set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set().

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the deleted cache item is the one whose cache ID is variables, contained in the cache_bootstrap cache bin.

As side note, cache_clear_all() could be also used to delete all the cache items whose IDs start with the string passed as first argument. For example, cache_clear_all('mymodule_', 'cache', TRUE) would delete the cache items having mymodule_cached_data or mymodule_long_calculus_result as cache ID.

To delete from the cache the cache item set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set().

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the deleted cache item is the one whose cache ID is variables, contained in the cache_bootstrap cache bin.

To delete from the cache the cache item set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set().

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the deleted cache item is the one whose cache ID is variables, contained in the cache_bootstrap cache bin.

As side note, cache_clear_all() could be also used to delete all the cache items whose IDs start with the string passed as first argument. For example, cache_clear_all('mymodule_', 'cache', TRUE) would delete the cache items having mymodule_cached_data or mymodule_long_calculus_result as cache ID.

shown how Drupal core uses cache_clear_all() to delete a single cache item
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

To delete from the cache the datacache item set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set().

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the deleted cache item is the one whose cache ID is variables, contained in the cache_bootstrap cache bin.

To delete from the cache the data set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

To delete from the cache the cache item set with cache_set($cache_id, $temp_data, 'cache', CACHE_TEMPORARY); it's enough to call cache_clear_all($cache_id, 'cache');. Despite the name, cache_clear_all() doesn't necessarily clear all the cache; it does so only when no parameter is passed to the function.

Usually Drupal core uses cache_clear_all() to clear all the cache. In some cases, it uses that function to clear a specific cache item, which is what Drupal core does in variable_set().

function variable_set($name, $value) {
  global $conf;
  db_merge('variable')->key(array('name' => $name))
    ->fields(array('value' => serialize($value)))
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
  $conf[$name] = $value;
}

In that code, the deleted cache item is the one whose cache ID is variables, contained in the cache_bootstrap cache bin.

Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Loading