-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Easy way to declare custom Cache #973
Comments
The Lines 342 to 344 in 965d6e8
You can probably subclass it and override it to use your own cache implementation. If you want to implement your own cache, consider implementing this abstract class Line 75 in 965d6e8
From what I see, there is no way to add a Cache class to cache settings since the Cache object itself takes in the settings when it's being constructed. All I can tell you is to subclass GatewayBot , set the _cache property to your own cache implementation, then use it.
But I think it would be better for the |
I see. The problem is you have to patch two places; Bot._cache and Bot._event_manager._cache. Maybe an extra option on Bot that accepts a cache class would be best. |
Yeah that's what I said in the last part of my reply. The |
I just realized, you don't need to override |
What's the actual use case for this though |
Maybe someone might want to use their own cache implementation. For example, I personally had thought of the idea to use Redis for cache. Even though not everyone will use their custom cache impl, having a pluggable cache seems like a nice feature |
This isn't a viable way to add an asynchronous cache, you'd have to have that as a separate thing |
Separate thing hmmm... Like what exactly? |
Adding/modifying an existing cache. For example, the current cache only stores existing values. What if I wanted to store None for deleted messages, so that I don't fetch non-existing messages repeatedly? An async cache would have to be seperate, but here's a custom cache I use right now: https://github.com/TrigonDev/Starboard/blob/main/starboard/cache.py |
BTW this example would likely fall under #880 (although it'd never quite apply to messages since that cache store is always incomplete) |
I think there is with a library like |
Summary
It would be nice if I could declare a cache class in CacheSettings. Currently you have to patch multiple things, including
Bot._cache
andBot._event_manager._cache
.Why is this needed?
To add to or modify the default cache.
Ideal implementation
An extra setting in CacheSettings for cache class; it should expect a subclass of CacheImpl. Then it can set
self._cache = cache_settings.cache_class(...)
, or something of the sort.Checklist
The text was updated successfully, but these errors were encountered: