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.

CommentFileSizeAuthor
#1 2325917-views_content_cache-1.patch5.79 KBguillaumev

Comments

guillaumev’s picture

Status: Active » Needs review
StatusFileSize
new5.79 KB

Here 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...

Exploratus’s picture

interesting

mxr576’s picture

I'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

mxr576’s picture

Status: Needs review » Reviewed & tested by the community

After a few weeks production usage, this looks ok for me.

jwilde’s picture

I'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

ray17n’s picture

Hi, 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)

idebr’s picture

This patch speeds up views displays up to 40%. Thanks guillaumev!

jdleonard’s picture

This patch seems to be working well for me, thanks!

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

My 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!

drunken monkey’s picture

Component: Framework » Views integration

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.