implement in memory cache
This commit is contained in:
parent
8563addf49
commit
ca2c990002
@ -9,6 +9,8 @@ UNSHORTEN = {
|
|||||||
't.co': unshorten_twitter
|
't.co': unshorten_twitter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CACHE = {}
|
||||||
|
|
||||||
app = FastAPI(docs_url=None, redoc_url=None)
|
app = FastAPI(docs_url=None, redoc_url=None)
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
@ -29,4 +31,10 @@ async def receive_url(url: Optional[str] = None):
|
|||||||
if domain not in UNSHORTEN:
|
if domain not in UNSHORTEN:
|
||||||
return {"error": f"cannot unshorten {domain}"}
|
return {"error": f"cannot unshorten {domain}"}
|
||||||
|
|
||||||
return UNSHORTEN[domain](url)
|
if url in CACHE:
|
||||||
|
unshortened = CACHE[url]
|
||||||
|
else:
|
||||||
|
unshortened = UNSHORTEN[domain](url)
|
||||||
|
CACHE[url] = unshortened
|
||||||
|
|
||||||
|
return unshortened
|
||||||
|
Loading…
Reference in New Issue
Block a user