The views_plugin_cache::get_output_key() method used to generate the cache key based on a hash that included, among other things, the actual results of the database query. This was very beneficial in terms of setting up a useful relationship between the output cache and the results cache —you could set the results cache to expire after 5 minutes, while leaving the output cache set to something much longer, and still guarantee that the output cache would regenerate if the database results changed.il
This feature was removed based on comments made in https://www.drupal.org/node/1055616#comment-6451790, indicating that it was redundant —since get_cache_key() already uses $this->view->build_info in the cache key, it wasn't necessary to pass the full result set. I disagree, given that build_info does not appear to contain enough information to be able to detect when the result set has changed.
Can we please add $this->view->results back into the $key_data array for the output cache? Again, this will make the following configuration possible:
Desired behavior:
- Given:
- Results cache times out after 5 minutes.
- Output cache times out after 6 days.
- $key_data for output cache key includes $this->view->result, as it did before
- When:
- One of the nodes in the result set changes, or a new node is added that would be part of the view's result set
- Then:
- The view will update to reflect those changes within, at most, 5 minutes, since the output cache key will be different.
Current behavior (not desired):
- Otherwise, Given:
- Results cache times out after 5 minutes.
- Output cache times out after 6 days.
- $key_data for output cache key does not include $this->view->result, as is now the case
- When:
- One of the nodes in the result set changes, or a new node is added that would be part of the view's result set
- Then:
- The view will not update to reflect those changes until the output cache times out, which could be up to 6 days, since the output cache key will not be different.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | time_based_output_cache-2628960-5.patch | 1.15 KB | fabianx |
Comments
Comment #2
jazzslider commentedAccidentally filed this under Drupal core, changing to Views.
Comment #3
dandaman commentedI agree this is an issue. To solve this, I added this line:
to
views_plugin_cache->get_output_key()inplugins/views_plugin_cache.inc:Comment #4
fabianx commentedYup, this is a regression from #1055616-152: Query arguments should be replaced before generating cache ID.
RTBC - I had the same (and more issues).
Comment #5
fabianx commentedHere is a proper patch that solves both regressions.
Comment #6
dawehnerMay I ask why we need this bugfix? Please add a inline comment why a) this should not be part of the get_cache_key() method and b) the variation on the build query is not enough, as that is what get_cache_key() does.
Comment #7
fabianx commented#6:
- a) First of all this is a regression and was in the original code base and was removed without reasoning.
- b) The build query does not contain the LIMIT clause at the point the cache key is created and therefore every AJAX request returns the same page over and over again.
e.g. the cache key is the same for all pages, but only when using a pager_element = 1.
This is very hard to reproduce so I opt-ed to restore the original behavior first.
Comment #8
dawehnerDo you understand why the limit is not on there?
Comment #9
fabianx commented#8 Unfortunately I have no idea and more unfortunately no time to debug right now.
I can only presume that the pager data is just added to the query afterwards as the paging works correctly - just the cache_key() is wrong.
Comment #11
dawehnerLet's fix the critical regression.
Comment #12
fabianx commentedThank you!
For anyone finding this issue, my issue was related to views_php, which was used on a project.
views_php does remove the paging mechanism of the database and instead always returns all results and filters those results, which means the cache key is the same for every page. Re-adding the $_GET parameters back however should never make the caching worse as that is what was in the original caching plugin for some years. And the referenced issue removing those took great care to not break views_php already.
And the output cache issue was obviously critical in itself.