66Functions:
77 cmp(f1, f2, shallow=True) -> int
88 cmpfiles(a, b, common) -> ([], [], [])
9+ clear_cache()
910
1011"""
1112
1213import os
1314import stat
1415from itertools import filterfalse
1516
16- __all__ = ['cmp' , 'dircmp' , 'cmpfiles' , 'DEFAULT_IGNORES' ]
17+ __all__ = ['clear_cache' , ' cmp' , 'dircmp' , 'cmpfiles' , 'DEFAULT_IGNORES' ]
1718
1819_cache = {}
1920BUFSIZE = 8 * 1024
2021
2122DEFAULT_IGNORES = [
2223 'RCS' , 'CVS' , 'tags' , '.git' , '.hg' , '.bzr' , '_darcs' , '__pycache__' ]
2324
25+ def clear_cache ():
26+ """Clear the filecmp cache."""
27+ _cache .clear ()
2428
2529def cmp (f1 , f2 , shallow = True ):
2630 """Compare two files.
@@ -39,7 +43,8 @@ def cmp(f1, f2, shallow=True):
3943 True if the files are the same, False otherwise.
4044
4145 This function uses a cache for past comparisons and the results,
42- with a cache invalidation mechanism relying on stale signatures.
46+ with a cache invalidation mechanism relying on stale signatures
47+ or by explicitly calling clear_cache().
4348
4449 """
4550
@@ -56,7 +61,7 @@ def cmp(f1, f2, shallow=True):
5661 if outcome is None :
5762 outcome = _do_cmp (f1 , f2 )
5863 if len (_cache ) > 100 : # limit the maximum size of the cache
59- _cache . clear ()
64+ clear_cache ()
6065 _cache [f1 , f2 , s1 , s2 ] = outcome
6166 return outcome
6267
0 commit comments