funkycache 1.0.5__tar.gz → 1.0.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {funkycache-1.0.5/src/funkycache.egg-info → funkycache-1.0.6}/PKG-INFO +1 -1
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache/storage.py +10 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache/version.py +1 -1
- {funkycache-1.0.5 → funkycache-1.0.6/src/funkycache.egg-info}/PKG-INFO +1 -1
- {funkycache-1.0.5 → funkycache-1.0.6}/tests/test_manager.py +28 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/tests/test_storage.py +3 -2
- {funkycache-1.0.5 → funkycache-1.0.6}/LICENSE +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/README.md +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/pyproject.toml +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/setup.cfg +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache/__init__.py +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache/manager.py +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache/py.typed +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache.egg-info/SOURCES.txt +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache.egg-info/dependency_links.txt +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache.egg-info/requires.txt +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/src/funkycache.egg-info/top_level.txt +0 -0
- {funkycache-1.0.5 → funkycache-1.0.6}/tests/test_integration.py +0 -0
|
@@ -347,6 +347,16 @@ class LazyCacheStorage[V](CacheStorage[V]):
|
|
|
347
347
|
self._underlying = self._create_underlying()
|
|
348
348
|
return self._underlying.get(key)
|
|
349
349
|
|
|
350
|
+
def close(self) -> None:
|
|
351
|
+
"""
|
|
352
|
+
Close the underlying storage.
|
|
353
|
+
"""
|
|
354
|
+
if self._underlying is None:
|
|
355
|
+
pass
|
|
356
|
+
if not hasattr(self._underlying, "close"):
|
|
357
|
+
return
|
|
358
|
+
self._underlying.close() # type: ignore
|
|
359
|
+
|
|
350
360
|
|
|
351
361
|
def _encode_key_as_json(key: dict[str, Any]) -> str:
|
|
352
362
|
"""
|
|
@@ -709,6 +709,34 @@ class TestFunkyCache:
|
|
|
709
709
|
assert greet("Alex") == "Bonjour Alex!"
|
|
710
710
|
assert calls == {"Alex": 2}
|
|
711
711
|
|
|
712
|
+
def test_lazy_sqlite_cache(self, tmp_path: Path) -> None:
|
|
713
|
+
"""
|
|
714
|
+
If you cache a function with SQLite but never call it, the underlying
|
|
715
|
+
database is never created.
|
|
716
|
+
|
|
717
|
+
This is a regression test for a bug in v1.0.5 where closing the
|
|
718
|
+
storage would create the database.
|
|
719
|
+
"""
|
|
720
|
+
p = tmp_path / "example.py"
|
|
721
|
+
|
|
722
|
+
p.write_text(
|
|
723
|
+
textwrap.dedent("""
|
|
724
|
+
from funkycache import FunkyCache
|
|
725
|
+
|
|
726
|
+
GREETING = "hello world"
|
|
727
|
+
|
|
728
|
+
cache = FunkyCache(storage="sqlite", root=".cache")
|
|
729
|
+
|
|
730
|
+
@cache.register
|
|
731
|
+
def greet() -> str:
|
|
732
|
+
return GREETING
|
|
733
|
+
""")
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
subprocess.check_call(["python3", str(p)], cwd=tmp_path)
|
|
737
|
+
|
|
738
|
+
assert not (tmp_path / ".cache").exists()
|
|
739
|
+
|
|
712
740
|
|
|
713
741
|
class TestMemoryFunkyCache(FunkyCacheTestSuite):
|
|
714
742
|
"""
|
|
@@ -289,8 +289,9 @@ class LazyCacheStorageTestSuite(CacheStorageTestSuite):
|
|
|
289
289
|
assert isinstance(storage, LazyCacheStorage)
|
|
290
290
|
assert storage._underlying is None
|
|
291
291
|
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
for name in ("does_not_exist1", "does_not_exist2", "does_not_exist3"):
|
|
293
|
+
with pytest.raises(AttributeError):
|
|
294
|
+
getattr(storage, name)
|
|
294
295
|
|
|
295
296
|
assert storage._underlying is not None
|
|
296
297
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|