1 cache_example.module cache_example_form_create_expiring_item($form, &$form_state)

Submit handler to create a new cache item with specified expiration.

Related topics

File

modules/examples/cache_example/cache_example.module, line 206
Hooks implementation for the Cache Example module.

Code

function cache_example_form_create_expiring_item($form, &$form_state) {
  $interval = $form_state['values']['expiration'];
  if ($interval == 'never_remove') {
    $expiration = CACHE_PERMANENT;
    $expiration_friendly = t('Never expires');
  }
  else {
    $expiration = time() + $interval;
    $expiration_friendly = format_date($expiration);
  }
  // Set the expiration to the actual Unix timestamp of the end of the required
  // interval.
  // An alternative syntax is to use the shortcut: cache_set('cache_example_expiring_item', $expiration_friendly, 'cache', $expiration);
  cache('cache')->set('cache_example_expiring_item', $expiration_friendly, $expiration);
  backdrop_set_message(t('cache_example_expiring_item was set to expire at %time', array('%time' => $expiration_friendly)));
}