title: Python re module's cache clearing
body: <p>While reading the documentation on Python <code>re</code> module I decided to have a look on <code>re.py</code> source code.</p>
  
  <p>When I opened it, I found this:</p>
  
  <pre><code>_cache = {}
  _MAXCACHE = 100
  
  def _compile(*key):
      cachekey = (type(key[0]),) + key
      p = _cache.get(cachekey)
      if p is not None:
          return p
  
      #...Here I skip some part of irrelevant to the question code...
  
      if len(_cache) &gt;= _MAXCACHE:
          _cache.clear()
      _cache[cachekey] = p
      return p
  </code></pre>
  
  <p>Why is the cache cleared using<code>_cache.clear()</code> when it reaches <code>_MAXCACHE</code> of entries? </p>
  
  <p>Is it common approach to clear cache completely and start from scratch? </p>
  
  <p>Why just not used the longest time ago cashed value is deleted?</p>