Index: django/templatetags/cache.py
===================================================================
--- django/templatetags/cache.py	(revision 6914)
+++ django/templatetags/cache.py	(working copy)
@@ -1,5 +1,4 @@
-from django.template import Library, Node, TemplateSyntaxError
-from django.template import resolve_variable
+from django.template import Library, Node, Variable, TemplateSyntaxError, VariableDoesNotExist
 from django.core.cache import cache
 from django.utils.encoding import force_unicode
 
@@ -13,9 +12,16 @@
         self.vary_on = vary_on
 
     def render(self, context):
+        try:
+            self.expire_time = int(self.expire_time)
+        except ValueError:
+            try:
+                self.expire_time = int(Variable(self.expire_time).resolve(context))
+            except (ValueError, TypeError, VariableDoesNotExist):
+                raise TemplateSyntaxError(u"Cannot resolve cache timeout! '%s' must be an integer." % self.expire_time)
         # Build a unicode key for this fragment and all vary-on's.
         cache_key = u':'.join([self.fragment_name] + \
-            [force_unicode(resolve_variable(var, context)) for var in self.vary_on])
+            [force_unicode(Variable(var).resolve(context)) for var in self.vary_on])
         value = cache.get(cache_key)
         if value is None:
             value = self.nodelist.render(context)
@@ -48,10 +54,6 @@
     tokens = token.contents.split()
     if len(tokens) < 3:
         raise TemplateSyntaxError(u"'%r' tag requires at least 2 arguments." % tokens[0])
-    try:
-        expire_time = int(tokens[1])
-    except ValueError:
-        raise TemplateSyntaxError(u"First argument to '%r' must be an integer (got '%s')." % (tokens[0], tokens[1]))
-    return CacheNode(nodelist, expire_time, tokens[2], tokens[3:])
+    return CacheNode(nodelist, tokens[1], tokens[2], tokens[3:])
 
 register.tag('cache', do_cache)
Index: tests/regressiontests/templates/tests.py
===================================================================
--- tests/regressiontests/templates/tests.py	(revision 6914)
+++ tests/regressiontests/templates/tests.py	(working copy)
@@ -877,12 +877,17 @@
             'cache04' : ('{% load cache %}{% cache 2 test %}cache04{% endcache %}', {}, 'cache03'),
             'cache05' : ('{% load cache %}{% cache 2 test foo %}cache05{% endcache %}', {'foo': 1}, 'cache05'),
             'cache06' : ('{% load cache %}{% cache 2 test foo %}cache06{% endcache %}', {'foo': 2}, 'cache06'),
-            'cache07' : ('{% load cache %}{% cache 2 test foo %}cache06{% endcache %}', {'foo': 1}, 'cache05'),
+            'cache07' : ('{% load cache %}{% cache 2 test foo %}cache07{% endcache %}', {'foo': 1}, 'cache05'),
+            'cache08' : ('{% load cache %}{% cache time test foo %}cache08{% endcache %}', {'foo': 2, 'time': 2}, 'cache06'),
+            'cache09' : ('{% load cache %}{% cache time test foo %}cache09{% endcache %}', {'foo': 3, 'time': -1}, 'cache09'),
+            'cache10' : ('{% load cache %}{% cache time test foo %}cache10{% endcache %}', {'foo': 3, 'time': -1}, 'cache10'),
 
-            # Raise exception if we dont have at least 2 args, first one integer.
-            'cache08' : ('{% load cache %}{% cache %}{% endcache %}', {}, template.TemplateSyntaxError),
-            'cache09' : ('{% load cache %}{% cache 1 %}{% endcache %}', {}, template.TemplateSyntaxError),
-            'cache10' : ('{% load cache %}{% cache foo bar %}{% endcache %}', {}, template.TemplateSyntaxError),
+            # Raise exception if we dont have at least 2 args, first one resolved to integer.
+            'cache11' : ('{% load cache %}{% cache %}{% endcache %}', {}, template.TemplateSyntaxError),
+            'cache12' : ('{% load cache %}{% cache 1 %}{% endcache %}', {}, template.TemplateSyntaxError),
+            'cache13' : ('{% load cache %}{% cache foo bar %}{% endcache %}', {}, template.TemplateSyntaxError),
+            'cache14' : ('{% load cache %}{% cache foo bar %}{% endcache %}', {'foo': 'fail'}, template.TemplateSyntaxError),
+            'cache15' : ('{% load cache %}{% cache foo bar %}{% endcache %}', {'foo': []}, template.TemplateSyntaxError),
 
             ### AUTOESCAPE TAG ##############################################
             'autoescape-tag01': ("{% autoescape off %}hello{% endautoescape %}", {}, "hello"),
