diff --git a/django/utils/cache.py b/django/utils/cache.py
index 9c566ae..29a2e2d 100644
--- a/django/utils/cache.py
+++ b/django/utils/cache.py
@@ -29,6 +29,7 @@ from django.core.cache import cache
 from django.utils.encoding import smart_str, iri_to_uri
 from django.utils.http import http_date
 from django.utils.hashcompat import md5_constructor
+from django.http import HttpRequest
 
 cc_delim_re = re.compile(r'\s*,\s*')
 
@@ -143,8 +144,10 @@ def _generate_cache_key(request, headerlist, key_prefix):
         value = request.META.get(header, None)
         if value is not None:
             ctx.update(value)
+    path = md5_constructor()
+    path.update(iri_to_uri(request.path))
     return 'views.decorators.cache.cache_page.%s.%s.%s' % (
-               key_prefix, iri_to_uri(request.path), ctx.hexdigest())
+               key_prefix, path.hexdigest(), ctx.hexdigest())
 
 def get_cache_key(request, key_prefix=None):
     """
@@ -158,8 +161,10 @@ def get_cache_key(request, key_prefix=None):
     """
     if key_prefix is None:
         key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
+    path = md5_constructor()
+    path.update(iri_to_uri(request.path))
     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
-                    key_prefix, iri_to_uri(request.path))
+                    key_prefix, path.hexdigest())
     headerlist = cache.get(cache_key, None)
     if headerlist is not None:
         return _generate_cache_key(request, headerlist, key_prefix)
@@ -183,8 +188,10 @@ def learn_cache_key(request, response, cache_timeout=None, key_prefix=None):
         key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
     if cache_timeout is None:
         cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
+    path = md5_constructor()
+    path.update(iri_to_uri(request.path))
     cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
-                    key_prefix, iri_to_uri(request.path))
+                    key_prefix, path.hexdigest())
     if response.has_header('Vary'):
         headerlist = ['HTTP_'+header.upper().replace('-', '_')
                       for header in cc_delim_re.split(response['Vary'])]
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
index fe365f9..a82d776 100644
--- a/tests/regressiontests/cache/tests.py
+++ b/tests/regressiontests/cache/tests.py
@@ -13,8 +13,8 @@ from django.conf import settings
 from django.core import management
 from django.core.cache import get_cache
 from django.core.cache.backends.base import InvalidCacheBackendError
-from django.http import HttpResponse
-from django.utils.cache import patch_vary_headers
+from django.http import HttpResponse, HttpRequest
+from django.utils.cache import patch_vary_headers, get_cache_key, learn_cache_key
 from django.utils.hashcompat import md5_constructor
 
 # functions/classes for complex data type tests
@@ -294,6 +294,23 @@ class FileBasedCacheTests(unittest.TestCase, BaseCacheTests):
 class CacheUtils(unittest.TestCase):
     """TestCase for django.utils.cache functions."""
 
+    def setUp(self):
+        self.path = '/cache/test/'
+        self.old_settings_key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
+        settings.CACHE_MIDDLEWARE_KEY_PREFIX = 'settingsprefix'
+
+    def tearDown(self):
+        settings.CACHE_MIDDLEWARE_KEY_PREFIX = self.old_settings_key_prefix
+
+    def _get_request(self, path):
+        request = HttpRequest()
+        request.META = {
+            'SERVER_NAME': 'testserver',
+            'SERVER_PORT': 80,
+        }
+        request.path = request.path_info = "/cache/%s" % path
+        return request
+
     def test_patch_vary_headers(self):
         headers = (
             # Initial vary, new headers, resulting vary.
@@ -314,6 +331,26 @@ class CacheUtils(unittest.TestCase):
             patch_vary_headers(response, newheaders)
             self.assertEqual(response['Vary'], resulting_vary)
 
+    def test_get_cache_key(self):
+        request = self._get_request(self.path)
+        response = HttpResponse()
+        key_prefix = 'localprefix'
+        # Expect None if no headers have been set yet.
+        self.assertEqual(get_cache_key(request), None)
+        # Set headers to an empty list.
+        learn_cache_key(request, response)
+        self.assertEqual(get_cache_key(request), 'views.decorators.cache.cache_page.settingsprefix.a8c87a3d8c44853d7f79474f7ffe4ad5.d41d8cd98f00b204e9800998ecf8427e')
+        # Verify that a specified key_prefix is taken in to account.
+        learn_cache_key(request, response, key_prefix=key_prefix)
+        self.assertEqual(get_cache_key(request, key_prefix=key_prefix), 'views.decorators.cache.cache_page.localprefix.a8c87a3d8c44853d7f79474f7ffe4ad5.d41d8cd98f00b204e9800998ecf8427e')
+
+    def test_learn_cache_key(self):
+        request = self._get_request(self.path)
+        response = HttpResponse()
+        response['Vary'] = 'Pony'
+        # Make sure that the Vary header is added to the key hash
+        learn_cache_key(request, response)
+        self.assertEqual(get_cache_key(request), 'views.decorators.cache.cache_page.settingsprefix.a8c87a3d8c44853d7f79474f7ffe4ad5.d41d8cd98f00b204e9800998ecf8427e')
 
 if __name__ == '__main__':
     unittest.main()
