##
4.7 #cache with test: expression and method conditions

The template:

      #cache test=$isDBUpdated
      This is a cached region.  $voom
      #end cache

(Analysis postponed: bug in Cheetah produces invalid Python.)

The template:

      #cache id='cache1', test=($isDBUpdated or $someOtherCondition)
      This is a cached region.  $voom
      #end cache

The output:

      This is a cached region.  Voom!

The first if-block in the generated code:

      RECACHE = True
      if not self._cacheData.has_key('36798144'):
          self._cacheIndex['cache1'] = '36798144'
      elif (VFS(SL,"isDBUpdated",1) or VFS(SL,"someOtherCondition",1)):
          RECACHE = True
      else:
          RECACHE = False

The second if-block is the same as in the previous example. If you leave out the `()` around the test expression, the result is the same, although it may be harder for the template maintainer to read.

You can even combine arguments, although this is of questionable value.

The template:

      #cache id='cache1', timer='30m', test=$isDBUpdated or $someOtherCondition
      This is a cached region.  $voom
      #end cache

The output:

      This is a cached region.  Voom!

The first if-block:

      RECACHE = True
      if not self._cacheData.has_key('88939345'):
          self._cacheIndex['cache1'] = '88939345'
          self.__cache88939345__refreshTime = currentTime() + 1800.0
      elif currentTime() > self.__cache88939345__refreshTime:
          self.__cache88939345__refreshTime = currentTime() + 1800.0
      elif VFS(SL,"isDBUpdated",1) or VFS(SL,"someOtherCondition",1):
          RECACHE = True
      else:
          RECACHE = False

We are planning to add a `'varyBy'` keyword argument in the future that will allow a separate cache instances to be created for a variety of conditions, such as different query string parameters or browser types. This is inspired by ASP.net's varyByParam and varyByBrowser output caching keywords. Since this is not implemented yet, I cannot provide examples here.