-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement caching system #73
Conversation
One thing that it doesn't seem to be implemented in class Backend(abc.ABC):
@abc.abstractmethod
async def get_with_ttl(self, key: str) -> Tuple[int, Optional[bytes]]:
raise NotImplementedError
@abc.abstractmethod
async def get(self, key: str) -> Optional[bytes]:
raise NotImplementedError
@abc.abstractmethod
async def set(self, key: str, value: bytes, expire: Optional[int] = None) -> None:
raise NotImplementedError
@abc.abstractmethod
async def clear(self, namespace: Optional[str] = None, key: Optional[str] = None) -> int:
raise NotImplementedError It's probably not super hard to create a null backend that doesn't do anything and always executes the route. |
I think this is now ready for review. I've made a few changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. I'll pull and test it out first before approving. Is there a way we can explicitly trigger the cache to clear, and wipe the redis or in-memory cache?
To allow clearing the cache I've added a function |
This implements caching for Valis queries.
Uses fastapi-cache to optionally cache Valis routes. Two backends are supported, Redis and memcached, which can be toggled using a new setting
cache_backend
(defaults toredis
butmemcached
does not require ).I added
cache
decorators to all the suggested routes in #69 plus some of the/query/list
ones except the main query. The library only supports caching GET requests.If this is a dealbreaker we can consider something different for those routes.On Redis, the key with the cached values is of the form
fastapi-cache:valis-cache:get:/query/list/cartons:[]
which includes the route and the query params used.Closes #69