twilight
twilight copied to clipboard
in-memory cache: don't pin cache to specific models
Instead reworking it to use generics with bounds for conversions allows the user to effectively swap out the models and thus what data is allocated/stored. They would only have to implement the traits to convert to these models, and can leave out any data they do not need/want cached to save on ram.
This way big savings in ram usage can be made, without having to build an entire custom cache from scratch, or having to maintain an own clone with pruned down models
The current API could be made to fit this with one type parameter/cached model. They could keep the current values as defaults (U = User, V = CachedVoiceState>
etc.)
Also requires a reworked / generic UpdateCache
trait. The cache requires 12 generics arguments as of right now.
Since there are a lot of different models, we could use a trait with associated types to customize them:
struct MyModels;
impl CacheModels for MyModels {
type Guild = CachedGuild;
type Member = CachedMember;
type Message = (); // not cached
// ...
}
The only downside is that associated types cannot have default values.