Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
brycedrennan committed Oct 30, 2020
1 parent 3f589a4 commit b5524ce
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tldextract/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,27 @@ def get_cache_dir():
Get a cache dir that we have permission to write to
Try to follow the XDG standard, but if that doesn't work fallback to the package directory
http://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
"""
try:
# http://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
xdg_cache_home = os.getenv("XDG_CACHE_HOME", None)
if xdg_cache_home is None:
user_home = os.getenv("HOME", None)
cache_dir = os.environ.get("TLDEXTRACT_CACHE", None)
if cache_dir is not None:
return cache_dir

xdg_cache_home = os.getenv("XDG_CACHE_HOME", None)
if xdg_cache_home is None:
user_home = os.getenv("HOME", None)
if user_home:
xdg_cache_home = os.path.join(user_home, ".cache")
pkg_id = get_pkg_unique_identifier()
cache_dir_default = os.path.join(xdg_cache_home, "python-tldextract", pkg_id)

return os.path.expanduser(os.environ.get("TLDEXTRACT_CACHE", cache_dir_default))
except TypeError: # noqa
# fallback to trying to use package directory itself
return os.path.join(os.path.dirname(__file__), ".suffix_cache/")
if xdg_cache_home is not None:
return os.path.join(xdg_cache_home, "python-tldextract", get_pkg_unique_identifier())

# fallback to trying to use package directory itself
return os.path.join(os.path.dirname(__file__), ".suffix_cache/")


class DiskCache:
"""Disk _cache that only works for jsonable values"""
NOT_SET = object()

def __init__(self, cache_dir, lock_timeout=20):
self.enabled = bool(cache_dir)
Expand Down

0 comments on commit b5524ce

Please sign in to comment.