Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove_all does not remove cache #927

Open
rkucmierowski opened this issue Apr 22, 2024 · 2 comments
Open

remove_all does not remove cache #927

rkucmierowski opened this issue Apr 22, 2024 · 2 comments
Labels

Comments

@rkucmierowski
Copy link

rkucmierowski commented Apr 22, 2024

Context

Is everything ok with remove_all cleanuping option for file cache?
According docs: When set to true (...) it will remove complete level directories for file caches instead of comparing each tile with a timestamp.

Actual Behavior

But if remove_all is set to True,
max_mtime = self.expire_timestamp(tile) equals 0 and tiles timestamp comparison is still performed,
so the condition stale = int(tile.timestamp) <= max_mtime evaluates to False and is_cached() returns True.

def is_cached(self, tile, dimensions=None):
"""
Return True if the tile is cached.
"""
if isinstance(tile, tuple):
tile = Tile(tile)
if tile.coord is None:
return True
cached = self.cache.is_cached(tile, dimensions=dimensions)
max_mtime = self.expire_timestamp(tile)
if cached and max_mtime is not None:
self.cache.load_tile_metadata(tile)
# file time stamp must be rounded to integer since time conversion functions
# mktime and timetuple strip decimals from seconds
stale = int(tile.timestamp) <= max_mtime
if stale:
cached = False
return cached

Then is_stale() returns False, which means that the tile has not expired and shouldn't be remove
def is_stale(self, tile, dimensions=None):
"""
Return True if tile exists _and_ is expired.
"""
if isinstance(tile, tuple):
tile = Tile(tile)
if self.cache.is_cached(tile, dimensions=dimensions):
# tile exists
if not self.is_cached(tile, dimensions=dimensions):
# expired
return True
return False
return False

Your Environment

Version used: MapProxy 1.16
Environment name and version: Python 3.7
Server type and version:
Operating System and version: Ubuntu
@simonseyock
Copy link
Contributor

simonseyock commented Jun 5, 2024

Thanks for reporting this! In my opinion the behavior of is_cached is correct, but is_stale should return True instead of False. I will look into this.

Edit: I think the description of is_cached is wrong and should actually be: Return True if the tile exists _and_ is not expired.

@simonseyock simonseyock added the bug label Jun 5, 2024
@simonseyock
Copy link
Contributor

simonseyock commented Jun 5, 2024

I assume you mean the remove_all option of the seeding cleanup tasks https://mapproxy.github.io/mapproxy/latest/seed.html#remove-all

There exists a test that covers exactly this case for the tile cache:
https://github.com/mapproxy/mapproxy/blob/master/mapproxy/test/system/test_seed.py#L193

The functions is_cached and is_stale are never called in this case. Can you provide further information about your configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants