Skip to content

Commit

Permalink
Merge pull request #181 from netomi/fix-path-of-redirects-db
Browse files Browse the repository at this point in the history
Fix storage location of redirect database for FileBackend cache.
  • Loading branch information
JWCook committed Oct 2, 2023
2 parents 72649f7 + 601ca38 commit 0b56f76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions aiohttp_client_cache/backends/filesystem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from contextlib import contextmanager
from os import listdir, makedirs
from os.path import abspath, dirname, expanduser, isabs, isfile, join
from os.path import abspath, expanduser, isabs, isfile, join
from pathlib import Path
from pickle import PickleError
from shutil import rmtree
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(
):
super().__init__(autoclose=autoclose, **kwargs)
self.responses = FileCache(cache_name, use_temp=use_temp, **kwargs)
db_path = join(dirname(self.responses.cache_dir), 'redirects.sqlite')
db_path = join(self.responses.cache_dir, 'redirects.sqlite')
self.redirects = SQLiteCache(db_path, 'redirects', **kwargs)


Expand Down Expand Up @@ -94,7 +94,7 @@ async def keys(self) -> AsyncIterable[str]:
yield filename

async def size(self) -> int:
return len(listdir(self.cache_dir))
return len(list(filter(lambda fn: not fn.endswith(".sqlite"), listdir(self.cache_dir))))

async def values(self) -> AsyncIterable[ResponseOrKey]:
async for key in self.keys():
Expand Down
13 changes: 13 additions & 0 deletions test/integration/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from aiohttp_client_cache.backends.base import BaseCache
from aiohttp_client_cache.backends.filesystem import FileBackend, FileCache
from aiohttp_client_cache.session import CachedSession
from test.conftest import CACHE_NAME
from test.integration import BaseBackendTest, BaseStorageTest

Expand Down Expand Up @@ -54,3 +55,15 @@ class TestFileBackend(BaseBackendTest):
@pytest.mark.skip(reason='Test not yet working for Filesystem backend')
async def test_gather(self):
super().test_gather()

async def test_redirect_cache_path(self):
async with self.init_session() as session:
assert isinstance(session, CachedSession)

cache = session.cache
assert isinstance(cache, FileBackend)

cache_dir = cache.responses.cache_dir
redirects_file = cache.redirects.filename

assert redirects_file.startswith(cache_dir)

0 comments on commit 0b56f76

Please sign in to comment.