In case of an exception thrown by the backend, Search API Cache plugins always cache an empty result.
The exception gets caught and the view is executed again with "abort" set to handle the errors:
catch (\Exception $e) {
$this->abort($e->getMessage());
// Recursion to get the same error behaviour as above.
$this->execute($view);
}
That triggers the Search API cache plugin selected for this view. This plugin just uses the cache configuration from the view and ignores the cache metadata set on the query.
According to #3133997: Avoid query caching in Search API when a Search API Solr Exception is thrown the backend should set max-age to 0 on the query before throwing an exception. But the current implementation. ignores that.
In general the cache plugin should respect the max-age any 3rd party module might have set on the query if that max-age is shorter than the configuration values.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3296006-9--exception_caching_test.patch | 2.66 KB | drunken monkey |
| #9 | 3296006-9--exception_caching_test--with_fix_reverted.patch | 5.27 KB | drunken monkey |
Comments
Comment #2
mkalkbrennerComment #3
mkalkbrennerSorry, wrong patch. Here's the right one.
BTW if max-age is 0 no cache entry should be written at all.
Comment #4
borisson_The approach here looks good, but I have some trouble understanding everything correctly.
this makes it really difficult to understand. Can we rewrite this? to make it clearer?
By reversing this, it might make it easier to read what is going on?
if ($expire === 0) {
return;
}
Comment #5
mkalkbrennerHere's a more readable and commented version.
Comment #6
borisson_Looks a lot better.
Comment #7
drunken monkeyLooks great, thanks a lot, both of you!
Fixed a typo and committed.
As we already have a Views caching test (
ViewsDisplayCachingTest), it would also be great to get test coverage for this fix. Would you mind writing one, Markus? (I chose to commit it without a test as you maintain the issue is urgent, but normally it should have test coverage. While at it, we could also add a test for #3295564: Views caching is broken with facets 2.0.4.)Comment #9
drunken monkeyFinally got round to writing the test for this.
Comment #12
drunken monkeyMerged.
Thanks again, everyone!