On high traffic sites, views caching can highly improve the rendering speed of pages. However, by default, both Views and Search API Views provide a time-based method for caching, which is great but has the issue that if a content is updated on the site, the update won't be shown in the view before the cache expires, which depending on what you set can be a long time.
To avoid this issue, Views content cache allows you to clear the views cache every time a content is updated, so you can get the best of both worlds: views are updated in real time, yet caching is also enabled to improve the speed of your pages.
However, Views content cache is not compatible with Search API views, in the same way that the default views cache is not compatible with Search API Views. In this case, I will provide a patch to add a caching mechanism for Search API Views baed on Views content cache.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 2325917-views_content_cache-1.patch | 5.79 KB | guillaumev |
Comments
Comment #1
guillaumev commentedHere is the patch...
Basically, it adds a caching method based on views content cache if the views_content_cache module is available. I have done some testing and it seems to work quite well...
Comment #2
Exploratus commentedinteresting
Comment #3
mxr576I've applied you patch, currently it seems, it is working well. I don't understand why nobody tested or reviewed your patch yet...
I will push this patch the RTBC after a few days testing.
Greetings, mxr576
Comment #4
mxr576After a few weeks production usage, this looks ok for me.
Comment #5
jwilde commentedI'm trying to get the patch to work but getting...
Fatal error: Call to a member function preExecute() on null in /var/www/html/mysite/sites/all/modules/contrib/_search/search_api/contrib/search_api_views/includes/plugin_cache.inc on line 90
Any ideas how to fix it. I'm using 7.x-1.20 search api and views content cache 7.x-3.0-alpha3. Thanks, Jim
Comment #6
ray17n commentedHi, I'm also getting the same error when I enable Search-specific cache:
"Fatal error: Call to a member function preExecute() on a non-object in ... search_api_views/includes/plugin_cache.inc on line 90"
I tried using the last dev versions:
Search API - Version: 7.x-1.20+3-dev
Facet API - Version: 7.x-2.x-dev
Search API Solr Search - Version: 7.x-1.11+2-dev
but I got the same. Then I discovered that I had a Views PHP field in the view, and deleting the field or disabling the Search-specfic Caching solves the issue (as rcodina says at https://www.drupal.org/node/1088776 #27)
Comment #7
idebr commentedThis patch speeds up views displays up to 40%. Thanks guillaumev!
Comment #8
jdleonardThis patch seems to be working well for me, thanks!
Comment #9
drunken monkeyMy apologies for not replying earlier! I try to look at every new issue that comes in, but now and again (for unknown reasons) I seem to miss one. Just thought I’d maybe check whether there were any RTBC issues and then this pops up. Again, my apologies!
(In the future, feel free to ping me via contact form or Slack if I haven’t replied after, say, two months. (Usually it’s not even a week, but sometimes a back log accumulates …))
Anyways, I haven’t tried the patch (don’t want to install that module, but as several people report it working perfectly (#5 and #6 seem like they’d have the exact same troubles with out existing cache plugin), and it also doesn’t break my installation which doesn’t have that module, I’m going to go ahead and just commit this.
I don’t think the
module_exists()is even needed in the class file, either, so I removed that.Anyways, thanks to all of you for your contribution!
Comment #11
drunken monkey