[Python-checkins] r86880 - in python/branches/py3k: Doc/library/functools.rst Doc/whatsnew/3.2.rst Lib/functools.py

raymond.hettinger python-checkins at python.org
Tue Nov 30 08:13:04 CET 2010


Author: raymond.hettinger
Date: Tue Nov 30 08:13:04 2010
New Revision: 86880

Log:
Neaten-up a bit.

Modified:
   python/branches/py3k/Doc/library/functools.rst
   python/branches/py3k/Doc/whatsnew/3.2.rst
   python/branches/py3k/Lib/functools.py

Modified: python/branches/py3k/Doc/library/functools.rst
==============================================================================
--- python/branches/py3k/Doc/library/functools.rst	(original)
+++ python/branches/py3k/Doc/library/functools.rst	Tue Nov 30 08:13:04 2010
@@ -72,10 +72,10 @@
 
    A `LRU (least recently used) cache
    <http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used>`_
-   is indicated when the pattern of calls changes over time, such as
-   when more recent calls are the best predictors of upcoming calls
+   works best when more recent calls are the best predictors of upcoming calls
    (for example, the most popular articles on a news server tend to
-   change every day).
+   change each day).  The cache's size limit assurs that caching does not
+   grow without bound on long-running processes such as web servers.
 
    .. versionadded:: 3.2
 

Modified: python/branches/py3k/Doc/whatsnew/3.2.rst
==============================================================================
--- python/branches/py3k/Doc/whatsnew/3.2.rst	(original)
+++ python/branches/py3k/Doc/whatsnew/3.2.rst	Tue Nov 30 08:13:04 2010
@@ -332,15 +332,13 @@
          c.execute('SELECT phonenumber FROM phonelist WHERE name=?', (name,))
          return c.fetchone()[0]
 
-  XXX: update for Issue 10586 changes to cache statistics API
-
   To help with choosing an effective cache size, the wrapped function is
-  instrumented with two attributes *cache_hits* and *cache_misses*:
+  instrumented with info function:
 
   >>> for name in user_requests:
   ...     get_phone_number(name)
-  >>> print(get_phone_number.cache_hits, get_phone_number.cache_misses)
-  4805 980
+  >>> get_phone_number.cache_info()
+  CacheInfo(maxsize=300, size=300, hits=4805, misses=980)
 
   If the phonelist table gets updated, the outdated contents of the cache can be
   cleared with:

Modified: python/branches/py3k/Lib/functools.py
==============================================================================
--- python/branches/py3k/Lib/functools.py	(original)
+++ python/branches/py3k/Lib/functools.py	Tue Nov 30 08:13:04 2010
@@ -121,16 +121,15 @@
 
     Arguments to the cached function must be hashable.
 
-    Significant statistics (maxsize, size, hits, misses) are
-      available through the f.cache_info() named tuple.
-    Clear the cache and statistics using f.cache_clear().
-    The underlying function is stored in f.__wrapped__.
+    View the cache statistics named tuple (maxsize, size, hits, misses) with
+    f.cache_info().  Clear the cache and statistics with f.cache_clear().
+    And access the underlying function with f.__wrapped__.
 
     See:  http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
 
     """
     # Users should only access the lru_cache through its public API:
-    #   cache_info, cache_clear, and f.__wrapped__
+    #       cache_info, cache_clear, and f.__wrapped__
     # The internals of the lru_cache are encapsulated for thread safety and
     # to allow the implementation to change (including a possible C version).
 
@@ -141,7 +140,7 @@
         cache_popitem = cache.popitem
         cache_renew = cache.move_to_end
         hits = misses = 0
-        kwd_mark = object()             # separate positional and keyword args
+        kwd_mark = object()             # separates positional and keyword args
         lock = Lock()
 
         @wraps(user_function)
@@ -165,7 +164,7 @@
             return result
 
         def cache_info():
-            """Report significant cache statistics"""
+            """Report cache statistics"""
             with lock:
                 return _CacheInfo(maxsize, len(cache), hits, misses)
 


More information about the Python-checkins mailing list