clear views cache on admin/build/modules

dww - May 10, 2007 - 18:22
Project:Views
Version:5.x-1.x-dev
Component:Code
Category:task
Priority:normal
Assigned:dww
Status:closed
Description

in working on views-support for signup.module, i've run into some tricky problems with the view cache and default views from other modules. basically, if your views support is conditionally loaded in hook_menu() in your primary module, not stuffed into a totally separate signup_views.module or something, then it's really hard for your module to export default views and have that work automatically without the admin needing to manually clear their views cache.

i tried something fancy like this:

<?php
function views_form_alter($form_id, &$form) {
  if (
$form_id == 'profile_field_form') {
   
views_invalidate_cache();
  }
  if (
$form_id == 'system_modules') {
   
$form['#submit']['views_system_modules_submit'] = array();
  }
}

function
views_system_modules_submit($form_id, $form_values) {
 
views_invalidate_cache();
 
drupal_set_message("Cleared views cache");
}
?>

and even that didn't work, due to the timing of when things are loaded and run. :( so, this seems to be the only fool-proof solution:

<?php
function views_form_alter($form_id, &$form) {
  if (
$form_id == 'profile_field_form' || $form_id == 'system_modules') {
   
views_invalidate_cache();
  }
}
?>

in other words, *always* clear the views cache, even if you just view the admin/build/modules page. ;) works fine. i'm not sure if this is a major performance problem, but it certainly makes things work more correctly without manual effort on the part of the admin.

AttachmentSize
views_modules_page_clear_cache.patch.txt641 bytes

#1

dww - May 10, 2007 - 18:33

merlin pointed out there was already code in hook_menu() trying to do this. however, since it was in $may_cache, it wasn't actually working. so, i removed that code block and moved the comment down to my change.

AttachmentSize
views_modules_page_clear_cache.patch_1.txt 1.23 KB

#2

dww - June 8, 2007 - 07:27

bump. ;) in http://drupal.org/node/149921, it looks like merlin thought this patch had already landed... anyone care to RTBC?

#3

moshe weitzman - June 8, 2007 - 11:15
Status:needs review» reviewed & tested by the community

yup - looks good.

#4

merlinofchaos - July 14, 2007 - 19:09
Status:reviewed & tested by the community» fixed

Commited to -dev.

#5

Anonymous - July 28, 2007 - 19:16
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.