<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -20,27 +20,33 @@ from django.utils.decorators import decorator_from_middleware_with_args, auto_ad
 from django.utils.cache import patch_cache_control, add_never_cache_headers
 from django.middleware.cache import CacheMiddleware
 
-def cache_page(*args):
+def cache_page(*args, **kwargs):
     # We need backwards compatibility with code which spells it this way:
     #   def my_view(): pass
     #   my_view = cache_page(my_view, 123)
     # and this way:
     #   my_view = cache_page(123)(my_view)
+    # and this:
+    #   my_view = cache_page(my_view, 123, key_prefix=&quot;foo&quot;)
+    # and this:
+    #   my_view = cache_page(123, key_prefix=&quot;foo&quot;)(my_view)
     # and possibly this way (?):
     #   my_view = cache_page(123, my_view)
 
     # We also add some asserts to give better error messages in case people are
     # using other ways to call cache_page that no longer work.
+    key_prefix = kwargs.pop('key_prefix', None)
+    assert not kwargs, &quot;The only keyword argument accepted is key_prefix&quot;
     if len(args) &gt; 1:
         assert len(args) == 2, &quot;cache_page accepts at most 2 arguments&quot;
         if callable(args[0]):
-            return decorator_from_middleware_with_args(CacheMiddleware)(args[1])(args[0])
+            return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[1], key_prefix=key_prefix)(args[0])
         elif callable(args[1]):
-            return decorator_from_middleware_with_args(CacheMiddleware)(args[0])(args[1])
+            return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], key_prefix=key_prefix)(args[1])
         else:
             assert False, &quot;cache_page must be passed either a single argument (timeout) or a view function and a timeout&quot;
     else:
-        return decorator_from_middleware_with_args(CacheMiddleware)(args[0])
+        return decorator_from_middleware_with_args(CacheMiddleware)(cache_timeout=args[0], key_prefix=key_prefix)
 
 def cache_control(**kwargs):
 </diff>
      <filename>django/views/decorators/cache.py</filename>
    </modified>
    <modified>
      <diff>@@ -361,6 +361,17 @@ then requests to ``/foo/1/`` and ``/foo/23/`` will be cached separately, as
 you may expect. But once a particular URL (e.g., ``/foo/23/``) has been
 requested, subsequent requests to that URL will use the cache.
 
+``cache_page`` can also take an optional keyword argument, ``key_prefix``, which
+works in the same way as the ``CACHE_MIDDLEWARE_KEY_PREFIX`` setting for the
+middleware.  It can be used like this::
+
+    my_view = cache_page(my_view, 60 * 15, key_prefix=&quot;site1&quot;)
+
+Or, using Python 2.4's decorator syntax::
+
+    @cache_page(60 * 15, key_prefix=&quot;site1&quot;)
+    def my_view(request):
+
 Specifying per-view cache in the URLconf
 ----------------------------------------
 </diff>
      <filename>docs/topics/cache.txt</filename>
    </modified>
    <modified>
      <diff>@@ -98,6 +98,8 @@ class DecoratorsTest(TestCase):
             return &quot;response&quot;
         my_view_cached = cache_page(123)(my_view)
         self.assertEqual(my_view_cached(HttpRequest()), &quot;response&quot;)
+        my_view_cached2 = cache_page(123, key_prefix=&quot;test&quot;)(my_view)
+        self.assertEqual(my_view_cached2(HttpRequest()), &quot;response&quot;)
 
     def test_cache_page_old_style(self):
         &quot;&quot;&quot;
@@ -107,6 +109,8 @@ class DecoratorsTest(TestCase):
             return &quot;response&quot;
         my_view_cached = cache_page(my_view, 123)
         self.assertEqual(my_view_cached(HttpRequest()), &quot;response&quot;)
+        my_view_cached2 = cache_page(my_view, 123, key_prefix=&quot;test&quot;)
+        self.assertEqual(my_view_cached2(HttpRequest()), &quot;response&quot;)
 
 class MethodDecoratorAdapterTests(TestCase):
     def test_auto_adapt_to_methods(self):</diff>
      <filename>tests/regressiontests/decorators/tests.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>af239e2c73ad177ca5480264a3f1b9c4c30bae8d</id>
    </parent>
  </parents>
  <author>
    <name>lukeplant</name>
    <email>lukeplant@bcc190cf-cafb-0310-a4f2-bffc1f526a37</email>
  </author>
  <url>http://github.com/tswicegood/django/commit/930f1adc9ae38f054b34ad259a691830bcfc6e84</url>
  <id>930f1adc9ae38f054b34ad259a691830bcfc6e84</id>
  <committed-date>2009-09-28T14:54:54-07:00</committed-date>
  <authored-date>2009-09-28T14:54:54-07:00</authored-date>
  <message>Added 'key_prefix' keyword argument to cache_page()

This was available before r11586, but undocumented.  It has now been
re-added with documentation and explicit support, as it seems like a useful
feature and people were using it before.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@11595 bcc190cf-cafb-0310-a4f2-bffc1f526a37</message>
  <tree>aa6c19928b34ea2513527d9ff374120ede19841d</tree>
  <committer>
    <name>lukeplant</name>
    <email>lukeplant@bcc190cf-cafb-0310-a4f2-bffc1f526a37</email>
  </committer>
</commit>
