I have view with caching of results set to never cache and output set to 5min, I looked into cache_views_data table and I have both results+output.

Comments

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new462 bytes

For it does not make sense to cache not the result, but cache the output. The output will not change, but the database would have to work.

Nonetheless: You are right, the cache is stored, but the cache is as far as i see, never loaded. Here is a small patch, which checks, on set, whether it should get stored.

bloto’s picture

Thank you for the patch,

I believe you should also add correction for cache_get in order to not try to read it from cache in case of never cache setting.

  /**
   * Get data from the cache.
   */
  function cache_get($type) {
    if ($this->options[$type .'_lifespan'] >= 0) {
      return parent::cache_get($type);
    }
    return FALSE;
  }

I am not sure If I understand how this works correctly but If the result from my next query will not change (I do not know if it will) then I have my html output ready, right? Will it speed my page generation time up or not then?

Regards

merlinofchaos’s picture

dereine is right. Why would you cache the output but not the query? You'll run the query and throw away the result, which is less performant.

I find this issue confusing.

merlinofchaos’s picture

Status: Needs review » Needs work

Setting needs work based on my comments in #3.

dawehner’s picture

Atleast this saves space in the cache table, thats ok to fix, i think

phillamb168’s picture

Just a quick note on this: for one of our production sites, this bug was causing some big problems. We are actually using the reverse of what bloto has described - the queries are cached (1 hour) but the HTML is not cached. Applying the patch in #1 along with the extra code in #2 appears to have fixed the issue.

esmerel’s picture

Status: Needs work » Closed (won't fix)

No updates to issue/patch in 3 months

ccw’s picture

This is really nasty.

I'm running 6.x-2.12. Views get cache options seem to be ignored.
I have a view, that should never be cached, because I send a 404 status header in the Empty text.

I've tried setting cache options to "None" and "Time base" rendered output to "Never". But I only get a 404, the first time I GET the view. All following GET's will 200 OK.

For some reason, responses to HEAD requests do have the desired status codes.

merlinofchaos’s picture

#8: Your issue has nothing to do with this closed issue. You shouldn't attempt to hijack issues.

That said, you seem to be assuming Views is responsible for the caching without actually confirming that, and are blaming Views. There are many layers of caching, and Views is very good about only caching when told to. I am 100% certain that Views does not cache when not configured to; almost nothing would ever really work if it cached unexpectedly.

ccw’s picture

tl;dr
Setting "cache mode" to "disabled" helped. I ended up working around it, by installing http://drupal.org/project/cacheexclude and setting an exception for the view page url. Any pointers to the real issue are welcome; so far it's 100% certainly not Views cache. And 100% certainly not something outside of Drupal :-)

I'm not trying to hijack issues [sic]. This issue seemed to address the same symptoms that were hurting me.

I'm not caching at the client (python-requests lib, urllib2, curl)
I'm not using a proxy.
I'm not caching in front of the webserver with a reverse proxy (Drupal 6 headers really make that pointless).
So it must be somewhere in Drupal.
The Drupal Performance "cache mode" is set to "normal" which has "no side effects", and setting the caching on the view to a non zero temporal, seemed to help. So I suspected Views, though the temporal setting could be a coinciding separate timings.

The different behaviour on HEAD and GET responses made it quite a chore to debug. Which is my stupid fault, I shouldn't have assumed the same headers and check the basic correctness of the view with HEAD requests (even though I was just interested in the headers), because the application was using GET. I was assuming since my Status was set in the body logic, and that was clearly executed for every HEAD, then *surely* it should be executed for the GET to. Not the case.

I basicly need something similar to #1295824: Add possibility to hide view or 404 if no results, perhaps among "No Results Behavior", but I don't wan't to "lead to a 404 page", just set the HTTP Status code to 404, if there is no node that conforms to the set filters. I do it now with a PHP code "empty text"

header('HTTP/1.1 404 Not Found');

Edit:
Using

drupal_set_header('HTTP/1.1 404 Not Found');

fixes the cache inconsistencies. It makes the response get cached with the right status header. Good enough.

johnv’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Status: Closed (won't fix) » Needs review
StatusFileSize
new674 bytes

This is a fresh patch, containing code from #1 and #2, against 3.6+dev

As merlinofchaos points out in #3 out: "Why would you cache the output but not the query"
That user error can be addressed in the settings UI.

johnv’s picture

Title: Views is writing cache of results when it is set to never cache » Time-based caching is writing cache when it is set to never cache

better title.

colan’s picture

Issue summary: View changes
StatusFileSize
new1.06 KB

Removed extra whitespace.

dawehner’s picture

I have the feeling that "0" could stand for infinity, so we might check for >= 0 ?

colan’s picture

Status: Needs review » Needs work

Not a bad idea.

les lim’s picture

Title: Time-based caching is writing cache when it is set to never cache » Time-based output caching is writing cache when it is set to "never cache"
Status: Needs work » Needs review
StatusFileSize
new674 bytes

#14 + 15 works for me.

johnv’s picture

Status: Needs review » Reviewed & tested by the community

#17 works for me.

colan’s picture

We've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.

If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.

We apologize for the trouble, and appreciate your patience.

johnv’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new674 bytes

This is a re-upload of #17.

johnv’s picture

Status: Needs review » Reviewed & tested by the community

  • colan committed 0c9fa05 on 7.x-3.x authored by johnv
    Issue #652610 by johnv, dawehner, colan, Les Lim: Stop caching when not...
colan’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.0.x-dev
Component: Miscellaneous » views.module
Status: Reviewed & tested by the community » Patch (to be ported)

Thanks!

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

catch’s picture

Status: Patch (to be ported) » Needs work

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

Version: 9.3.x-dev » 7.x-dev
Status: Needs work » Fixed
Issue tags: +Bug Smash Initiative

I just tested this on Drupal 9.4.x, standard install, and found that caching is working correctly, with the caveat that this is the first time I have looked closely at views caching and the tables. I used the a duplicate of the content view and played around with the various settings and could not create a situation where the caching or lack of it was not working as expected.

I think the thing to do here is move it back to Drupal 7 and restore the fixed status.

Status: Fixed » Closed (fixed)

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