original_docstring: Least-recently-used cache decorator.
  
      Arguments to the cached function must be hashable.
      Cache performance statistics stored in f.hits and f.misses.
      Clear the cache with f.clear().
      http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
  
      
docstring: Least-recently-used cache decorator.
  Arguments to the cached function must be hashable.
docstring_tokens: Least - recently - used cache decorator . Arguments to the cached function must be hashable .
code: def lru_cache(maxsize=100):
      '''Least-recently-used cache decorator.
  
      Arguments to the cached function must be hashable.
      Cache performance statistics stored in f.hits and f.misses.
      Clear the cache with f.clear().
      http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
  
      '''
      maxqueue = maxsize * 10
      def decorating_function(user_function,
              len=len, iter=iter, tuple=tuple, sorted=sorted, KeyError=KeyError):
          cache = {}                  # mapping of args to results
          queue = collections.deque() # order that keys have been used
          refcount = Counter()        # times each key is in the queue
          sentinel = object()         # marker for looping around the queue
          kwd_mark = object()         # separate positional and keyword args
  
          # lookup optimizations (ugly but fast)
          queue_append, queue_popleft = queue.append, queue.popleft
          queue_appendleft, queue_pop = queue.appendleft, queue.pop
  
          @functools.wraps(user_function)
          def wrapper(*args, **kwds):
              # cache key records both positional and keyword args
              key = args
              if kwds:
                  key += (kwd_mark,) + tuple(sorted(kwds.items()))
  
              # record recent use of this key
              queue_append(key)
              refcount[key] += 1
  
              # get cache entry or compute if not found
              try:
                  result = cache[key]
                  wrapper.hits += 1
              except KeyError:
                  result = user_function(*args, **kwds)
                  cache[key] = result
                  wrapper.misses += 1
  
                  # purge least recently used cache entry
                  if len(cache) > maxsize:
                      key = queue_popleft()
                      refcount[key] -= 1
                      while refcount[key]:
                          key = queue_popleft()
                          refcount[key] -= 1
                      del cache[key], refcount[key]
  
              # periodically compact the queue by eliminating duplicate keys
              # while preserving order of most recent access
              if len(queue) > maxqueue:
                  refcount.clear()
                  queue_appendleft(sentinel)
                  for key in filterfalse(refcount.__contains__,
                                          iter(queue_pop, sentinel)):
                      queue_appendleft(key)
                      refcount[key] = 1
  
  
              return result
  
          def clear():
              cache.clear()
              queue.clear()
              refcount.clear()
              wrapper.hits = wrapper.misses = 0
  
          wrapper.hits = wrapper.misses = 0
          wrapper.clear = clear
          return wrapper
      return decorating_function
code_tokens: def lru_cache ( maxsize = 100 ) : maxqueue = maxsize * 10 def decorating_function ( user_function , len = len , iter = iter , tuple = tuple , sorted = sorted , KeyError = KeyError ) : cache = { } queue = collections . deque ( ) refcount = Counter ( ) sentinel = object ( ) kwd_mark = object ( ) queue_append , queue_popleft = queue . append , queue . popleft queue_appendleft , queue_pop = queue . appendleft , queue . pop @ functools . wraps ( user_function ) def wrapper ( * args , ** kwds ) : key = args if kwds : key += ( kwd_mark , ) + tuple ( sorted ( kwds . items ( ) ) ) queue_append ( key ) refcount [ key ] += 1 try : result = cache [ key ] wrapper . hits += 1 except KeyError : result = user_function ( * args , ** kwds ) cache [ key ] = result wrapper . misses += 1 if len ( cache ) > maxsize : key = queue_popleft ( ) refcount [ key ] -= 1 while refcount [ key ] : key = queue_popleft ( ) refcount [ key ] -= 1 del cache [ key ] , refcount [ key ] if len ( queue ) > maxqueue : refcount . clear ( ) queue_appendleft ( sentinel ) for key in filterfalse ( refcount . __contains__ , iter ( queue_pop , sentinel ) ) : queue_appendleft ( key ) refcount [ key ] = 1 return result def clear ( ) : cache . clear ( ) queue . clear ( ) refcount . clear ( ) wrapper . hits = wrapper . misses = 0 wrapper . hits = wrapper . misses = 0 wrapper . clear = clear return wrapper return decorating_function
short_docstring: Least-recently-used cache decorator.
short_docstring_tokens: Least - recently - used cache decorator .
comment: '''Least-recently-used cache decorator.
  
      Arguments to the cached function must be hashable.
      Cache performance statistics stored in f.hits and f.misses.
      Clear the cache with f.clear().
      http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
  
      '''$SEP$# mapping of args to results$SEP$# order that keys have been used$SEP$# times each key is in the queue$SEP$# marker for looping around the queue$SEP$# separate positional and keyword args$SEP$# lookup optimizations (ugly but fast)$SEP$# cache key records both positional and keyword args$SEP$# record recent use of this key$SEP$# get cache entry or compute if not found$SEP$# purge least recently used cache entry$SEP$# periodically compact the queue by eliminating duplicate keys$SEP$# while preserving order of most recent access