views_plugin_cache_time.inc

  1. 3.x plugins/views_plugin_cache_time.inc
  2. 2.x plugins/views_plugin_cache_time.inc

File

plugins/views_plugin_cache_time.inc
View source
  1. <?php
  2. /**
  3. * Simple caching of query results for Views displays.
  4. */
  5. class views_plugin_cache_time extends views_plugin_cache {
  6. function option_defaults(&$options) {
  7. $options['results_lifespan'] = 3600;
  8. $options['output_lifespan'] = 3600;
  9. }
  10. function options_form(&$form, &$form_state) {
  11. $options = array(60, 300, 1800, 3600, 21600, 518400);
  12. $options = drupal_map_assoc($options, 'format_interval');
  13. $options = array(-1 => t('Never cache')) + $options;
  14. $form['results_lifespan'] = array(
  15. '#type' => 'select',
  16. '#title' => t('Query results'),
  17. '#description' => t('The length of time raw query results should be cached.'),
  18. '#options' => $options,
  19. '#default_value' => $this->options['results_lifespan'],
  20. );
  21. $form['output_lifespan'] = array(
  22. '#type' => 'select',
  23. '#title' => t('Rendered output'),
  24. '#description' => t('The length of time rendered HTML output should be cached.'),
  25. '#options' => $options,
  26. '#default_value' => $this->options['output_lifespan'],
  27. );
  28. }
  29. function summary_title() {
  30. return format_interval($this->options['results_lifespan'], 1) . '/' . format_interval($this->options['output_lifespan'], 1);
  31. }
  32. function cache_expire($type) {
  33. if ($lifespan = $this->options[$type . '_lifespan']) {
  34. $cutoff = time() - $lifespan;
  35. return $cutoff;
  36. }
  37. else {
  38. return FALSE;
  39. }
  40. }
  41. function cache_set_expire($type) {
  42. if ($lifespan = $this->options[$type . '_lifespan']) {
  43. return time() + $lifespan;
  44. }
  45. else {
  46. return CACHE_PERMANENT;
  47. }
  48. }
  49. }