Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Use caching.disk_only_cache for make_so
Browse files Browse the repository at this point in the history
  • Loading branch information
JDBetteridge committed Aug 19, 2024
1 parent b35ff86 commit 4b33593
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 144 deletions.
9 changes: 6 additions & 3 deletions pyop2/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def __getitem__(self, key):
"""
filepath = Path(self.cachedir, key[0][:2], key[0][2:] + key[1])
try:
with self.open(filepath, "rb") as fh:
with self.open(filepath, mode="rb") as fh:
value = self.read(fh)
except FileNotFoundError:
raise KeyError("File not on disk, cache miss")
Expand All @@ -285,7 +285,7 @@ def __setitem__(self, key, value):

tempfile = basedir.joinpath(f"{k2}_p{os.getpid()}.tmp")
filepath = basedir.joinpath(k2)
with self.open(tempfile, "wb") as fh:
with self.open(tempfile, mode="wb") as fh:
self.write(fh, value)
tempfile.rename(filepath)

Expand Down Expand Up @@ -359,6 +359,8 @@ def get(self, key, default=None):
self.hit += 1
return value

# JBTODO: Only instrument get, since we have to use get and get item in wrapper
# OR... find away around the hack in compilation.py
def __getitem__(self, key):
try:
value = super().__getitem__(key)
Expand Down Expand Up @@ -465,7 +467,8 @@ def wrapper(*args, **kwargs):

if value is CACHE_MISS:
value = func(*args, **kwargs)
return local_cache.setdefault(key, value)
local_cache[key] = value
return local_cache[key]

return wrapper
return decorator
Expand Down
Loading

0 comments on commit 4b33593

Please sign in to comment.