Skip to content

Commit

Permalink
Use newly released hishel in-memory cache (#6644)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored Jan 18, 2024
1 parent 47771cb commit cee9d2d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
20 changes: 2 additions & 18 deletions edb/server/protocol/auth_ext/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import hishel
import httpx

from edb.common import lru


class HttpClient(httpx.AsyncClient):
def __init__(
Expand All @@ -33,7 +31,8 @@ def __init__(
self.edgedb_orig_base_url = urllib.parse.quote(base_url, safe='')
base_url = edgedb_test_url
cache = hishel.AsyncCacheTransport(
transport=httpx.AsyncHTTPTransport(), storage=InMemoryStorage()
transport=httpx.AsyncHTTPTransport(),
storage=hishel.AsyncInMemoryStorage(capacity=5),
)
super().__init__(*args, base_url=base_url, transport=cache, **kwargs)

Expand All @@ -46,18 +45,3 @@ async def get(self, path, *args, **kwargs):
if self.edgedb_orig_base_url:
path = f'{self.edgedb_orig_base_url}/{path}'
return await super().get(path, *args, **kwargs)


class InMemoryStorage(hishel._async._storages.AsyncBaseStorage):
def __init__(self, maxsize=5):
super().__init__()
self._storage = lru.LRUMapping(maxsize=maxsize)

async def store(self, key: str, response, request, metadata):
self._storage[key] = (response, request, metadata)

async def retreive(self, key: str):
return self._storage.get(key, None)

async def aclose(self):
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies = [
'setproctitle~=1.2',

'httpx~=0.24.1',
'hishel==0.0.18',
'hishel==0.0.21',
'argon2-cffi~=23.1.0',
'aiosmtplib~=2.0',
]
Expand Down

0 comments on commit cee9d2d

Please sign in to comment.