docs: def parse(url):
      """Parses a cache URL."""
      config = {}
  
      url = urlparse.urlparse(url)
      # Handle python 2.6 broken url parsing
      path, query = url.path, url.query
      if '?' in path and query == '':
          path, query = path.split('?', 1)
  
      cache_args = dict([(key.upper(), ';'.join(val)) for key, val in
                         urlparse.parse_qs(query).items()])
  
      # Update with environment configuration.
      backend = BACKENDS.get(url.scheme)
      if not backend:
          raise Exception('Unknown backend: "{0}"'.format(url.scheme))
  
      config['BACKEND'] = BACKENDS[url.scheme]
  
      redis_options = {}
      if url.scheme == 'hiredis':
          redis_options['PARSER_CLASS'] = 'redis.connection.HiredisParser'
  
      # File based
      if not url.netloc:
          if url.scheme in ('memcached', 'pymemcached', 'djangopylibmc'):
              config['LOCATION'] = 'unix:' + path
  
          elif url.scheme in ('redis', 'hiredis'):
              match = re.match(r'.+?(?P<db>\d+)', path)
              if match:
                  db = match.group('db')
                  path = path[:path.rfind('/')]
              else:
                  db = '0'
              config['LOCATION'] = 'unix:%s:%s' % (path, db)
          else:
              config['LOCATION'] = path
      # URL based
      else:
          # Handle multiple hosts
          config['LOCATION'] = ';'.join(url.netloc.split(','))
  
          if url.scheme in ('redis', 'hiredis'):
              if url.password:
                  redis_options['PASSWORD'] = url.password
              # Specifying the database is optional, use db 0 if not specified.
              db = path[1:] or '0'
              port = url.port if url.port else 6379
              config['LOCATION'] = "redis://%s:%s/%s" % (url.hostname, port, db)
  
      if redis_options:
          config.setdefault('OPTIONS', {}).update(redis_options)
  
      if url.scheme == 'uwsgicache':
          config['LOCATION'] = config.get('LOCATION', 'default') or 'default'
  
      # Pop special options from cache_args
      # https://docs.djangoproject.com/en/1.10/topics/cache/#cache-arguments
      options = {}
      for key in ['MAX_ENTRIES', 'CULL_FREQUENCY']:
          val = cache_args.pop(key, None)
          if val is not None:
              options[key] = int(val)
      if options:
          config.setdefault('OPTIONS', {}).update(options)
  
      config.update(cache_args)
  
      return config