Skip to content

Commit

Permalink
Make the number of threads configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Feb 17, 2022
1 parent 7ec27c1 commit 7f16b96
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/fscacher/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

lgr = logging.getLogger(__name__)

DEFAULT_THREADS = 60


class PersistentCache(object):
"""Persistent cache providing @memoize and @memoize_path decorators
Expand All @@ -21,7 +23,7 @@ class PersistentCache(object):

_cache_var_values = (None, "", "clear", "ignore")

def __init__(self, name=None, tokens=None, envvar=None):
def __init__(self, name=None, tokens=None, envvar=None, walk_threads=None):
"""
Parameters
Expand All @@ -34,6 +36,8 @@ def __init__(self, name=None, tokens=None, envvar=None):
envvar: str, optional
Name of the environment variable to query for cache settings; if not
set, `FSCACHER_CACHE` is used
walk_threads: int, optional
Number of threads to use when traversing directory hierarchies
"""
dirs = appdirs.AppDirs("fscacher")
self._cache_file = op.join(dirs.user_cache_dir, (name or "cache"))
Expand All @@ -54,6 +58,7 @@ def __init__(self, name=None, tokens=None, envvar=None):
self.clear()
self._ignore_cache = cntrl_value == "ignore"
self._tokens = tokens
self._walk_threads = walk_threads or DEFAULT_THREADS

def clear(self):
try:
Expand Down Expand Up @@ -142,9 +147,8 @@ def fingerprinter(*args, **kwargs):
# and we memoize actually that function
return fingerprinter

@staticmethod
def _get_dir_fingerprint(dirpath):
def _get_dir_fingerprint(self, dirpath):
dprint = DirFingerprint()
for path, fprint in walk(dirpath):
for path, fprint in walk(dirpath, threads=self._walk_threads):
dprint.add_file(path, fprint)
return dprint

0 comments on commit 7f16b96

Please sign in to comment.