I can't find how would I disable caching for certain view in Drupal 5.3 + views 1.6. Could somebody help me = give a lead? It is needed to provide a block + page with random content (teaser list). Sort set to random.

Setting is_cacheable in view_view table to 0 didn't help. The view is still caching with this setting.

Comments

soupp’s picture

The solution I found http://drupal.org/project/cacheexclude

But it's only partial. It excludes the page but it does not work for block.

The result is here: http://www.drupalsites.net/random

merlinofchaos’s picture

Status: Active » Closed (works as designed)

Views does not do any content caching of its own. I believe you must be talking about the page cache, but page caching happens at a level that Views cannot control. There isn't anything Views can do about this.

In particular, if you have a block that needs to be different very page load, you basically cannot use page caching.

soupp’s picture

Thanks merlinofchaos. Your post just proved I'm not missing anything now.

Actually I was talking about both: page and block. But as long as block is a part of html output for a page I see now that the block can't be (non/re)cached individually not depending on the whole page.

The situation is a bit tricky with views blocks with random sorted content... but it is really by design. So it's or performance or more dynamic content.

kanani’s picture

Issue tags: +caching, +views

One of the ways I handled this was to:

  1. write a small module that calls my view
  2. add the path to cacheexclude
  3. use javascript to load the view results into the block

It gracefully degrades as well. If javascript is enabled, you get the noncached content, if its disabled, you get the cached results.

I'm loading it into a div in a page, but there's no reason you couldn't load it into a block.

Module code:

/**
 * Implementation of hook_menu().
 */
function pgsp_random_images_menu() {
 
  $items['nocache/imageheader'] = array(
    'title' => 'Random Header Image',
    'page callback' => 'random_image_headers',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
    
  );
  return $items;
}

function random_image_headers(){
  print views_embed_view('Random_Image_Blocks', 'block_2');
  exit;
}

Javascript code:

var loadRandomHeader = function(){
    $postUrl = "/nocache/imageheader"; 
     $.ajax({
            type: "POST",
            url: $postUrl,
            success: function(xml){
                $("#random-image-header").fadeOut(1000).html(xml).fadeIn(1000);
            }
    });
}

if (Drupal.jsEnabled) {
  $(document).ready(function() {
    loadRandomHeader();
 });
}

Marko B’s picture

Nice solution kanani!