Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

[feature | breaking] Smart cache for Client.get* methods #76

Open
curz46 opened this issue Jul 22, 2019 · 2 comments
Open

[feature | breaking] Smart cache for Client.get* methods #76

curz46 opened this issue Jul 22, 2019 · 2 comments
Labels
breaking 0.7 Breaking changes for the 0.7 release of the library enhancement

Comments

@curz46
Copy link
Contributor

curz46 commented Jul 22, 2019

Motivation
Currently the library presents two options when accessing some data with a snowflake e.g. user, channel, guild, etc:

  • Get from cache via Cache
  • Fetch from the API

A common requirement is that the user needs to fetch some data by using the cache if it exists and the API if it doesn't.

Description
Add options keyword list to every function in Alchemy.Client which supports :cached. The default value is true. When true, fetch from the cache if it exists, otherwise carry out the API request. When false simply carry out the API request.

Affected Functions

Client...
+ get_user/1
+ get_current_guilds/1
+ get_channel/1
+ get_guild/1
+ get_channels/1
+ get_member/1
+ get_roles/1
# get_member_list/1
# get_DMs/1
# get_message/1
# get_reactions/1
# get_channel_invites/1
# get_pins/1
# get_invite/1
# get_invites/1
& get_bans/1
& get_regions/1
& get_intergrations/1
& create_DM/1

Legend
+ Cached already
# Probably should be cached (if not already)
& Maybe should be cached?

Note: I don't know what the library does to cache information that these methods would provide as they are received as events. I still think we should add caching of that information as that is done by many other bot libraries and there is no reason not to remember what Discord tells us. A few of the methods maybe we shouldn't cache depending on if there is an event which would tell us if that information changes (get_integrations?).

@cronokirby cronokirby added breaking 0.7 Breaking changes for the 0.7 release of the library enhancement labels Jul 22, 2019
@cronokirby
Copy link
Owner

Some of these APIs don't map 1:1 onto a caching Cache. function, but we should still try and pull stuff from the cache even if it means multiple calls.

@curz46
Copy link
Contributor Author

curz46 commented Jul 22, 2019

Do you think all the methods I listed should have smart cache? On the topic of cache, I've noticed that member caching seems to be a little... non-existent. On what circumstances does a member get cached right now? The function Cache.load_guild_members also seems like it does nothing related to the cache.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking 0.7 Breaking changes for the 0.7 release of the library enhancement
Projects
None yet
Development

No branches or pull requests

2 participants