Block: DRUPAL_NO_CACHE not working I have a block that displays an item fetched from the database at random. The block has DRUPAL_NO_CACHE as cache parameter. However, when visiting the page as anonymous user with the cache on, the item never changes.

Some code:

function foo_block_info() {
  $blocks = array();

  $blocks['foo'] = array(
    'info' =&gt; t('Foo'), 
    'cache' =&gt; DRUPAL_NO_CACHE,
  );

  return $blocks;
}

function foo_block_view($delta = '') {
  if ($delta == 'foo') {
    $block = array(
      'content' =&gt; theme(
        'foo_block',
          array(
            'item' =&gt; entity_get_controller('foo')-&gt;get_random_foo(),
          )
        ),
    );
    return $block;
  }
}

function foo_theme($existing, $type, $theme, $path) {
  return array(
    'foo_block' =&gt; array(
      'template' =&gt; 'foo-block',
      'arguments' =&gt; array(
        'item' =&gt; NULL,
      ),
    ),
  );
}


I suspect it's a Drupal Core bug, I've checked the forums but can't really find a solution for Drupal 7.

I know I could insert the item in the DOM with AJAX, but that's a last resort.
If you are caching the whole page (which is off by default in D7) then BLOCK_NO_CACHE will not make a difference on a block. Because while the block is not cached, the page is. 

I think what you may want is the esi api module it allows you to use ajax to render the blocks.