Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changed the way cache specifiers are parsed.

Allows us to reuse the same code in multiple places, avoiding new and
interesting bugs (the testing framework had a DIY version that was slightly
wrong, for example). Fixed #9833.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@9936 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b740706707aed9f057a2f8badc31bc87997c6142 1 parent d772369
Malcolm Tredinnick authored March 01, 2009
11  django/core/cache/__init__.py
@@ -31,7 +31,12 @@
31 31
     'dummy': 'dummy',
32 32
 }
33 33
 
34  
-def get_cache(backend_uri):
  34
+def parse_backend_uri(backend_uri):
  35
+    """
  36
+    Converts the "backend_uri" into a cache scheme ('db', 'memcached', etc), a
  37
+    host and any extra params that are required for the backend. Returns a
  38
+    (scheme, host, params) tuple.
  39
+    """
35 40
     if backend_uri.find(':') == -1:
36 41
         raise InvalidCacheBackendError, "Backend URI must start with scheme://"
37 42
     scheme, rest = backend_uri.split(':', 1)
@@ -48,6 +53,10 @@ def get_cache(backend_uri):
48 53
     if host.endswith('/'):
49 54
         host = host[:-1]
50 55
 
  56
+    return scheme, host, params
  57
+
  58
+def get_cache(backend_uri):
  59
+    scheme, host, params = parse_backend_uri(backend_uri)
51 60
     if scheme in BACKENDS:
52 61
         module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, [''])
53 62
     else:
9  django/db/backends/creation.py
@@ -312,11 +312,12 @@ def create_test_db(self, verbosity=1, autoclobber=False):
312 312
         self.connection.close()
313 313
         settings.DATABASE_NAME = test_database_name
314 314
         settings.DATABASE_SUPPORTS_TRANSACTIONS = self._rollback_works()
315  
-        
  315
+
316 316
         call_command('syncdb', verbosity=verbosity, interactive=False)
317 317
 
318 318
         if settings.CACHE_BACKEND.startswith('db://'):
319  
-            cache_name = settings.CACHE_BACKEND[len('db://'):]
  319
+            from django.core.cache import parse_backend_uri
  320
+            _, cache_name, _ = parse_backend_uri(settings.CACHE_BACKEND)
320 321
             call_command('createcachetable', cache_name)
321 322
 
322 323
         # Get a cursor (even though we don't need one yet). This has
@@ -363,7 +364,7 @@ def _create_test_db(self, verbosity, autoclobber):
363 364
                 sys.exit(1)
364 365
 
365 366
         return test_database_name
366  
-    
  367
+
367 368
     def _rollback_works(self):
368 369
         cursor = self.connection.cursor()
369 370
         cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
@@ -375,7 +376,7 @@ def _rollback_works(self):
375 376
         cursor.execute('DROP TABLE ROLLBACK_TEST')
376 377
         self.connection._commit()
377 378
         return count == 0
378  
-        
  379
+
379 380
     def destroy_test_db(self, old_database_name, verbosity=1):
380 381
         """
381 382
         Destroy a test database, prompting the user for confirmation if the

0 notes on commit b740706

Please sign in to comment.
Something went wrong with that request. Please try again.