Skip to content

Commit

Permalink
improvement: do not fail request when cache item can not be persisted
Browse files Browse the repository at this point in the history
  • Loading branch information
czerwonk committed Oct 30, 2023
1 parent 8bc50e4 commit ff96eff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion thumbor/cache/expire_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __write(self, _file):
max_age = 0

_file.write(str.encode(str(max_age)))

if self.max_age_shared is not None:
_file.write(str.encode("," + str(self.max_age_shared)))

Expand Down
2 changes: 1 addition & 1 deletion thumbor/cache/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get(self, path):
exists, max_age, max_age_shared = self.exists(path)
if not exists:
return FileCacheResult(False)

with open(path, "rb") as source_file:
return FileCacheResult(True, source_file.read(), max_age, max_age_shared)

Expand Down
2 changes: 1 addition & 1 deletion thumbor/cache/prune_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def prune_expired_links(dir: str, file_cache: FileCache):
if os.path.isdir(f) and not name == "files":
prune_expired_links(f, file_cache)
continue

if os.path.isfile(f) and f.endswith(file_cache.EXPIRE_EXT):
prune_file_if_expired(f, file_cache)
continue
Expand Down
11 changes: 7 additions & 4 deletions thumbor/result_storages/file_storage_cache_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ async def put(self, image_bytes):
return

symlink_abspath = self.normalize_path(self.context.request.url)
self.cache.put(symlink_abspath,
image_bytes,
self.context.request.max_age,
self.context.request.max_age_shared)
try:
self.cache.put(symlink_abspath,
image_bytes,
self.context.request.max_age,
self.context.request.max_age_shared)
except IOError as e:
logger.error("[RESULT_STORAGE] error persisting item to result cache: %s", e.strerror)


async def get(self):
Expand Down
13 changes: 9 additions & 4 deletions thumbor/storages/file_storage_cache_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ async def put(self, path, file_bytes):
return

file_abspath = self.path_on_filesystem(path)
self.cache.put(file_abspath,
file_bytes,
self.context.request.max_age,
self.context.request.max_age_shared)
try:
self.cache.put(file_abspath,
file_bytes,
self.context.request.max_age,
self.context.request.max_age_shared)
except IOError as e:
logger.error("[STORAGE] error persisting cache item: %s", e.strerror)
return

return path


Expand Down

0 comments on commit ff96eff

Please sign in to comment.