Skip to content

Commit

Permalink
separate cache into folders by asset type (#908)
Browse files Browse the repository at this point in the history
* separate cache into folders by asset type

* ensure cache subfolders
  • Loading branch information
oscarlevin authored Jan 22, 2025
1 parent 7db949b commit 27a2a1f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 6 additions & 3 deletions pretext/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,12 @@ def generate_assets(
if clean:
self.clean_assets()

# Ensure that the generated_cache directory exists:
if not self.generated_cache_abspath().exists():
self.generated_cache_abspath().mkdir(parents=True, exist_ok=True)
# Ensure that the generated_cache directories exist:
for subdir in ["latex-image", "asymptote", "sageplot"]:
if not (self.generated_cache_abspath() / subdir).exists():
(self.generated_cache_abspath() / subdir).mkdir(
parents=True, exist_ok=True
)
log.debug(
f"Using cached assets in {self.generated_cache_abspath()} where possible."
)
Expand Down
6 changes: 2 additions & 4 deletions pretext/project/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def individual_latex_image(
asset_file = Path(latex_image).resolve()
outformats = ["png", "pdf", "svg", "eps"] if outformat == "all" else [outformat]
cache_files = {
ext: cache_asset_filename(asset_file, ext, "latex_image", cache_dir)
ext: cache_asset_filename(asset_file, ext, "latex-image", cache_dir)
for ext in outformats
}
output_files = {
Expand Down Expand Up @@ -135,8 +135,6 @@ def cache_asset_filename(
hash = hashlib.md5()
# hash the asset file
hash.update(asset_content)
# include the asset_type in hash
hash.update(asset_type.encode())
asset_hash = hash.hexdigest()
# create the cache file name
return cache_dir / f"{asset_hash}.{extension}"
return cache_dir / asset_type / f"{asset_hash}.{extension}"

0 comments on commit 27a2a1f

Please sign in to comment.