0

Problem

I have a view powered by the Search API, which uses the views inbuilt caching - "Search Specific" in order to provide better performance.

However I also run a number of theming alterations in:

theme_preprocess_views_view_unformatted

However this code appears to be skipped when the views caching kicks in. Is this by design or an I encountering a bug? If it's not, how have people gotten around this sort of thing before?

Re-creation

  • Clear all caches Load page - Code runs correctly
  • Refresh the page a number of times usually between 2 & 5
  • Refresh the page - Code is skipped

I've been testing if the code is skipped by including:

function theme_preprocess_views_view(&$vars) {
  ...
  watchdog('test', 'This chunk of code has just run');
  ...
}
0

I was misusing theme_preprocess_views_view_unformatted.

I'm running views caching, search specific (I think this may also apply to time specific) in order to cache the results of the view.

This caches the HTML of the view and means that the entire view creation, render and theming steps are skipped. When the view calls the search the correct HTML is returned.

However they do have to be run originally to build the cache. (For some reason it kicks in after a random number of refreshes? Perhaps there's simply a delay on creating the cache.)

I was using watchdog to log when the code runs and so obviously this only runs until the cache is created. This won't be an issue if everything you're doing in theme_preprocess_views_view_unformatted alters the HTML because that will be cached the first time it happens. However I was using it to add text to header based on the results of the view, which obviously didn't work.

This was possibly muddled by the fact that I run Varnish & Authcache on my live environment so I think this would cache the initial version (before the search cache is built) and thus stop me from re-creating the bug on my live version.

Make sure you're aware of all your caches and how they run!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.