-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(py): expose python caching utilities
- Loading branch information
Showing
3 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
__all__ = pyfuzon.__all__ | ||
|
||
from .matcher import TermMatcher | ||
from .cache import get_cache_key, get_cache_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Caching utilities for pyfuzon. | ||
This module provides functions to help manage the cache of TermMatchers. | ||
Cache keys are built by fuzon using the sorted source paths. For each path, | ||
a stamp is computed as follows (missing values are replaced by empty strings): | ||
+ file path: {path}-{size}-{last-modified-datetime} | ||
+ url: {url}-{etag-checksum}-{last-modified-datetime} | ||
All stamps are then concatenated and hash of the result is used as the cache key. | ||
Cache paths adhere to the following specifications: | ||
+ Linux: XDG base / user directory | ||
+ Windows: Known folder API | ||
+ MacOS: Standard Directories guidelines | ||
For more information, see: https://github.com/dirs-dev/dirs-rs | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
from .pyfuzon import get_cache_key as _get_cache_key | ||
from .pyfuzon import get_cache_path as _get_cache_path | ||
|
||
def get_cache_key(sources: list[str]) -> str: | ||
"""Return a deterministic cache key based on a collection of source paths.""" | ||
return _get_cache_key(sources) | ||
|
||
def get_cache_path(sources: list[str]) -> Path: | ||
"""Return a full platform-specific cache path based on a collection of source paths.""" | ||
return Path(_get_cache_path(sources)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters