Skip to content

Commit

Permalink
feat: set cache to 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
r3tr0ananas committed Jul 12, 2024
1 parent 9f62806 commit 15d7eb0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.3"
__version__ = "1.1.4"
6 changes: 3 additions & 3 deletions api/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def to_dict(self) -> ImageData:
"sources": self.sources
}

def to_file_response(self, raw: bool = False) -> FileResponse:
def to_file_response(self, raw: bool = False, expire: str = "300") -> FileResponse:
"""Returns file response object."""
if raw is False:
downscaled_image = self.downscale_image()
Expand All @@ -87,15 +87,15 @@ def to_file_response(self, raw: bool = False) -> FileResponse:
downscaled_image,
media_type="image/webp",
headers = {
"Expires": "0",
"Expires": expire,
"x-image-id": self.id
}
)

return FileResponse(
self.path,
headers = {
"Expires": "0",
"Expires": expire,
"x-image-id": self.id
}
)
4 changes: 2 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ async def get_metadata(id: str):
}
},
)
@limiter.limit(f"{RATE_LIMIT}/second")
@limiter.limit(f"{RATE_LIMIT}/second")
async def random_image(request: Request, category: str = None, raw: bool = False):
image = agac.get_random(category)

return image.to_file_response(raw)
return image.to_file_response(raw, expire="0")

@app.get(
"/search",
Expand Down

0 comments on commit 15d7eb0

Please sign in to comment.