]> granicus.if.org Git - python/commitdiff
Crude but effective hack to clear the parser cache every so often.
authorGuido van Rossum <guido@python.org>
Fri, 27 Dec 1996 15:26:15 +0000 (15:26 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 27 Dec 1996 15:26:15 +0000 (15:26 +0000)
(Fred Drake.)

Lib/urlparse.py

index 571ef0eb0c6194716b2eaa49b7e12b3e8ffb8e88..91775333c7328177e6de77cdf968bfee0fcf5153 100644 (file)
@@ -19,9 +19,11 @@ uses_fragment = ['ftp', 'hdl', 'http', 'gopher', 'news', 'nntp', 'wais',
 # Characters valid in scheme names
 scheme_chars = string.letters + string.digits + '+-.'
 
+MAX_CACHE_SIZE = 2000
 _parse_cache = {}
 
 def clear_cache():
+    """Clear the parse cache."""
     global _parse_cache
     _parse_cache = {}
 
@@ -35,6 +37,8 @@ def urlparse(url, scheme = '', allow_framents = 1):
        key = url, scheme, allow_framents
        if _parse_cache.has_key(key):
            return _parse_cache[key]
+       if len(_parse_cache) >= MAX_CACHE_SIZE: # avoid runaway growth
+           clear_cache()
        netloc = path = params = query = fragment = ''
        i = string.find(url, ':')
        if i > 0: