clear views cache on admin/build/modules
| Project: | Views |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | dww |
| Status: | closed |
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.
| Attachment | Size |
|---|---|
| views_modules_page_clear_cache.patch.txt | 641 bytes |

#1
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.
#2
bump. ;) in http://drupal.org/node/149921, it looks like merlin thought this patch had already landed... anyone care to RTBC?
#3
yup - looks good.
#4
Commited to -dev.
#5