feat: Enhance caching mechanism with MD5 hashing for instance identifiers
This commit is contained in:
BIN
dist/renamer-0.5.7-py3-none-any.whl
vendored
Normal file
BIN
dist/renamer-0.5.7-py3-none-any.whl
vendored
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "renamer"
|
||||
version = "0.5.6"
|
||||
version = "0.5.7"
|
||||
description = "Terminal-based media file renamer and metadata viewer"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
|
||||
@@ -31,6 +31,8 @@ def cached_method(ttl_seconds: int = 3600) -> Callable:
|
||||
|
||||
# Use instance identifier (file_path for extractors)
|
||||
instance_id = getattr(self, 'file_path', str(id(self)))
|
||||
if isinstance(instance_id, Path):
|
||||
instance_id = hashlib.md5(str(instance_id).encode('utf-8')).hexdigest()
|
||||
|
||||
# Create hash from args and kwargs (excluding self)
|
||||
param_str = json.dumps((args, kwargs), sort_keys=True, default=str)
|
||||
|
||||
@@ -5,6 +5,7 @@ from .mediainfo_extractor import MediaInfoExtractor
|
||||
from .fileinfo_extractor import FileInfoExtractor
|
||||
from .tmdb_extractor import TMDBExtractor
|
||||
from .default_extractor import DefaultExtractor
|
||||
import hashlib
|
||||
|
||||
|
||||
class MediaExtractor:
|
||||
@@ -13,8 +14,8 @@ class MediaExtractor:
|
||||
@classmethod
|
||||
def create(cls, file_path: Path, cache=None, ttl_seconds: int = 21600):
|
||||
"""Factory method that returns cached object if available, else creates new."""
|
||||
cache_key = f"extractor_{hashlib.md5(str(file_path).encode('utf-8')).hexdigest()}"
|
||||
if cache:
|
||||
cache_key = f"extractor_{file_path}"
|
||||
cached_obj = cache.get_object(cache_key)
|
||||
if cached_obj:
|
||||
print(f"Loaded MediaExtractor object from cache for {file_path.name}")
|
||||
@@ -25,7 +26,6 @@ class MediaExtractor:
|
||||
|
||||
# Cache the object
|
||||
if cache:
|
||||
cache_key = f"extractor_{file_path}"
|
||||
cache.set_object(cache_key, instance, ttl_seconds)
|
||||
print(f"Cached MediaExtractor object for {file_path.name}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user