Skip to content

Commit

Permalink
Update server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Jun 13, 2024
1 parent e116ae1 commit 8de208e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/performance/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ async def set(self, key, value):
async def close(self, *_):
await self.cache.close()

cache = web.AppKey("cache", CacheManager)

async def handler_get(req):
try:
data = await req.app["cache"].get("testkey")
data = await req.app[cache].get("testkey")
if data:
return web.Response(text=data)
except asyncio.TimeoutError:
return web.Response(status=404)

data = str(uuid.uuid4())
await req.app["cache"].set("testkey", data)
await req.app[cache].set("testkey", data)
return web.Response(text=str(data))


def run_server(backend: str) -> None:
app = web.Application()
app["cache"] = CacheManager(backend)
app.on_shutdown.append(app["cache"].close)
app[cache] = CacheManager(backend)
app.on_shutdown.append(app[cache].close)
app.router.add_route("GET", "/", handler_get)
web.run_app(app)

0 comments on commit 8de208e

Please sign in to comment.