twilight icon indicating copy to clipboard operation
twilight copied to clipboard

in-memory cache: don't pin cache to specific models

Open AEnterprise opened this issue 2 years ago • 3 comments

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

AEnterprise avatar Jan 01 '22 19:01 AEnterprise

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.)

vilgotf avatar May 20 '22 20:05 vilgotf

Also requires a reworked / generic UpdateCache trait. The cache requires 12 generics arguments as of right now.

vilgotf avatar May 20 '22 20:05 vilgotf

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.

baptiste0928 avatar Sep 16 '22 07:09 baptiste0928