code: public function isWithinCachedBlock(Mage_Core_Block_Abstract $block) {
          $step = $block;
  	$i = 0;
          while ($i++ < 20 && $step instanceof Mage_Core_Block_Abstract) {
              if (!is_null($step->getCacheLifetime())) {
                  return true;
              }
              $step = $step->getParentBlock();
          }
          return false;
      }
docs: Check if a block is within another one that is cached
  
  @param Mage_Core_Block_Abstract $block
  @return bool
  @author Fabrizio Branca
  @since 2011-01-24