-
-
Notifications
You must be signed in to change notification settings - Fork 319
Cache rework #1647
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
Closed
Closed
Cache rework #1647
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
2c09f3a
first cache structuring
Plerx2493 addd239
use generic cache methods
Plerx2493 a4b8ec2
impl DiscordMemoryCache
Plerx2493 0a0be2e
Add better configs
Plerx2493 5cb135d
Use primary constructors, move files and edit nits
Plerx2493 6281180
Even better configs and more generic cache impl
Plerx2493 16c5242
Use reflection to get keyGenMethods
Plerx2493 4b28c4b
Own CacheEntryOptions, impl static helper methods for CacheKeys
Plerx2493 7e520fa
Nuke old caches
Plerx2493 4db91dc
Add TransportGuild
Plerx2493 15a8214
DiscordGuild cache updates
Plerx2493 1b218df
much pain
Plerx2493 12f9ab0
rename Namespace and some pain
Plerx2493 3ab1f18
Replace old cache methods and start to apply new caching, tldr muuch …
Plerx2493 643e64b
Update Guild and Channel gateway event dispatch
Plerx2493 cdd4379
more time in DiscordClient.Dispatch and i will get insane
Plerx2493 982c851
start the auditlog pain again
Plerx2493 c4f3f9c
CachedEntity v1.5
Plerx2493 613e9ec
Start the second rundown on dispatch to add CachedEntity
Plerx2493 5bde3f6
i fogor
Plerx2493 e9eea0a
Merge branch 'master' into fix/cacheRework
Plerx2493 17ebabe
Dispatch readability and auditlog parser v3
Plerx2493 56db129
auditlog nullability
Plerx2493 2435d7f
Move presences to new cache and continue to update dispatch
Plerx2493 28b4abe
Remove hidden api call
Plerx2493 8d690ca
Merge branch 'master' into fix/cacheRework-merge
Plerx2493 06cb86b
fix merge issue
Plerx2493 951e9b0
merge and fix some nullability problems
Plerx2493 c280da2
start docs
Plerx2493 efe7021
rename some variables and methods acording to the editor config
Plerx2493 37a05dd
fix DiscordMessage
Plerx2493 61836e0
Fix DiscordGuild, DiscordChannel and a bit more
Plerx2493 d98dbfe
fix Channel#PermissionsForMember and start to fix some cnext attributes
Plerx2493 891b180
Fix ShardedClient, some renaming and some other fixes
Plerx2493 4ee9361
Fix voicestates
Plerx2493 81d7596
Merge branch 'master' into fix/cacheRework
Plerx2493 05f590f
fix more stuff
Plerx2493 0b00df4
started fixing message
Plerx2493 36470c5
More fixing
Plerx2493 465b777
GetGuild - withCounts und withChannels
Plerx2493 03b0b2e
Handle DiscordMessageSticker.GuildId is null
Plerx2493 efc7770
Fix DiscordWidgetSettings and DiscordWidget in DiscordApiClient
Plerx2493 fdf6f4b
Rename BaseDiscordClient._guilds to _guildIds
Plerx2493 51e9e47
Fix permission calculation and some minor things in DiscordChannel
Plerx2493 9e3852c
Don´t have a dublicate/override cache in DiscordClient because the ba…
Plerx2493 44bded8
Use cache when fetching guild in default
Plerx2493 b93e1c0
Fix dm channel caching in ApiClient
Plerx2493 a5edfe1
Forgot a _guilds to _guildIds rename
Plerx2493 e9fa536
Use new cache in DiscordEmoji static methods
Plerx2493 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| namespace DSharpPlus.Caching; | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using DSharpPlus.Entities; | ||
|
|
||
| /// <summary> | ||
| /// Configuration for the cache how long to keep items in the cache. This configuration is only used by <see cref="DiscordMemoryCache"/> and is ignored if you provide your own implementation of <see cref="IDiscordCache"/>. | ||
| /// </summary> | ||
| /// <remarks>The default implementation of <see cref="IDiscordCache"/> only supports timebased expiration </remarks> | ||
| public record CacheConfiguration | ||
| { | ||
| public Dictionary<Type, CacheEntryOptions> MemoryCacheEntryOptions { get; set; } = new() | ||
| { | ||
| {typeof(DiscordGuild), new CacheEntryOptions(){SlidingExpiration = TimeSpan.FromMinutes(60)}}, | ||
| {typeof(DiscordChannel), new CacheEntryOptions(){SlidingExpiration = TimeSpan.FromMinutes(60)}}, | ||
| {typeof(DiscordMessage), new CacheEntryOptions(){SlidingExpiration = TimeSpan.FromMinutes(60)}}, | ||
| {typeof(DiscordMember), new CacheEntryOptions(){SlidingExpiration = TimeSpan.FromMinutes(60)}}, | ||
| {typeof(DiscordUser), new CacheEntryOptions(){SlidingExpiration = TimeSpan.FromMinutes(60)}}, | ||
| {typeof(DiscordPresence), new CacheEntryOptions(){SlidingExpiration = TimeSpan.FromMinutes(60)}} | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| namespace DSharpPlus.Caching; | ||
|
|
||
| using System; | ||
| using Microsoft.Extensions.Caching.Memory; | ||
|
|
||
| public class CacheEntryOptions | ||
| { | ||
| /// <summary> | ||
| /// Sliding expiration for the cache entry | ||
| /// </summary> | ||
| /// <exception cref="ArgumentOutOfRangeException"></exception> | ||
| public TimeSpan? SlidingExpiration { get; set; } | ||
|
|
||
|
|
||
| /// <summary> | ||
| /// Absolute expiration for the cache entry relative to creation | ||
| /// </summary> | ||
| /// <exception cref="ArgumentOutOfRangeException"></exception> | ||
|
|
||
| public TimeSpan? AbsoluteExpirationRelativeToCreation { get; set; } | ||
|
|
||
|
|
||
| internal MemoryCacheEntryOptions ToMemoryCacheEntryOptions() | ||
| { | ||
| if (this.AbsoluteExpirationRelativeToCreation is null && this.SlidingExpiration is null) | ||
| { | ||
| throw new ArgumentException("Either SlidingExpiration or AbsoluteExpirationRelativeToCreation must be set"); | ||
| } | ||
|
|
||
| if | ||
| ( | ||
| this.AbsoluteExpirationRelativeToCreation is not null && | ||
| this.SlidingExpiration is not null && | ||
| this.AbsoluteExpirationRelativeToCreation < this.SlidingExpiration | ||
| ) | ||
| { | ||
| throw new ArgumentException("AbsoluteExpirationRelativeToCreation must be greater than SlidingExpiration"); | ||
| } | ||
|
|
||
| MemoryCacheEntryOptions options = new(); | ||
|
|
||
| if (this.AbsoluteExpirationRelativeToCreation is not null) | ||
| { | ||
| options.AbsoluteExpirationRelativeToNow = this.AbsoluteExpirationRelativeToCreation; | ||
| } | ||
|
|
||
| if (this.SlidingExpiration is not null) | ||
| { | ||
| options.SlidingExpiration = this.SlidingExpiration; | ||
| } | ||
|
|
||
| return options; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.