question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: State and Cache providers

See original GitHub issue

Proposal

Memory usage is a big issue within the library, developers have minimal control on how entities are stored in state. The proposal is to allow developers to fully customize the way Discord.Net stores entities in memory.

Foxbot has the first part of this covered with the IStateProvider allowing users to control how entities are fetched-stored to and from the cache. The state provider allows for downloading entities if they don’t exist within the cache for almost all gateway models and events.

The ICacheProvider is something I’ve been thinking about for way too long. I’ve finalized my idea on implementing this into Discord.Net. For each entity that can be cached ex IGuildMember there will be a IGuildMemberModel interface that allows us to have multiple ways to implement converting to and from strong-typed entities to models. We can make the api model Discord.API.Member and make it inherit the IGuildMemberModel interface and take in the interface for constructing a SocketGuildMember or RestGuildMember entity. Developers can create their own models that inherit IGuildMemberModel for example a class that converts itself to a protobuf buffer and pass that to the state provider to use to create an entity.

The term “state provider” and “cache provider” are two separate things, the state provider determines how entities are retrieved and stored while the cache provider stores to and fetches from the cache. Take this flow diagram as some more explanation behind this:

dnet-state-cache-flow

Things to note

The state provider will have to return the interface types of entities ex IGuild, IUser, etc due to the ability to fetch from rest if the behavior is enabled, this will cause a lot of gateway events to have to use interfaces due to this.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
budgetdevvcommented, Apr 14, 2022

Yeah since they’re task.run under the hood 👀

0reactions
AddressXceptioncommented, Jan 20, 2023

appreciate the updates. in the short term I’m unblocked by just holding onto object state in memory while requests are in-flight. I’m working on a project that is using this library so I’m here to help in any way I can.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add ability to store/cache result in state to avoid "will be ...
It would be good if there is some method to enable the caching of the result in the state unless the input configuration...
Read more >
Caching in Apollo Client
Apollo Client stores the results of your GraphQL queries in a local, normalized, in-memory cache. This enables Apollo Client to respond almost immediately ......
Read more >
Advanced topics on caching in Apollo Client
This article describes special cases and considerations when using the Apollo Client cache. Bypassing the cache. Sometimes you shouldn't use the cache for...
Read more >
Distributed Caching — The Only Guide You'll Ever Need
This write-up is an in-depth guide on Distributed Cache. It does cover all the frequently asked questions about it such as What is...
Read more >
Setting cache providers in HCL Commerce
Starting with HCL Commerce Version 9.1, all caches are automatically configured to use the HCL Cache. However, the cache provider for each cache...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found