@@ -82,10 +82,10 @@ class CacheImpl(cache.MutableCache):
8282 "_settings" ,
8383 )
8484
85- _dm_channel_entries : collections .ExtendedMutableMapping [snowflakes .Snowflake , snowflakes .Snowflake ]
8685 # For the sake of keeping things clean, the annotations are being kept separate from the assignment here.
8786 _me : typing .Optional [users .OwnUser ]
8887 _emoji_entries : collections .ExtendedMutableMapping [snowflakes .Snowflake , cache_utility .KnownCustomEmojiData ]
88+ _dm_channel_entries : collections .ExtendedMutableMapping [snowflakes .Snowflake , snowflakes .Snowflake ]
8989 _guild_channel_entries : collections .ExtendedMutableMapping [snowflakes .Snowflake , channels .GuildChannel ]
9090 _guild_entries : collections .ExtendedMutableMapping [snowflakes .Snowflake , cache_utility .GuildRecord ]
9191 _invite_entries : collections .ExtendedMutableMapping [str , cache_utility .InviteData ]
@@ -104,7 +104,6 @@ class CacheImpl(cache.MutableCache):
104104
105105 def __init__ (self , app : traits .RESTAware , settings : config .CacheSettings ) -> None :
106106 self ._app = app
107- self ._me = None
108107 self ._settings = settings
109108 self ._create_cache ()
110109
@@ -113,7 +112,8 @@ def settings(self) -> config.CacheSettings:
113112 return self ._settings
114113
115114 def _create_cache (self ) -> None :
116- self ._dm_channel_entries = collections .FreezableDict ()
115+ self ._me = None
116+ self ._dm_channel_entries = collections .LimitedCapacityCacheMap (limit = self ._settings .max_dm_channel_ids )
117117 self ._emoji_entries = collections .FreezableDict ()
118118 self ._guild_channel_entries = collections .FreezableDict ()
119119 self ._guild_entries = collections .FreezableDict ()
@@ -142,21 +142,33 @@ def clear(self) -> None:
142142 self ._create_cache ()
143143
144144 def clear_dm_channel_ids (self ) -> cache .CacheView [snowflakes .Snowflake , snowflakes .Snowflake ]:
145+ if not self ._is_cache_enabled_for (config .CacheComponents .DM_CHANNEL_IDS ):
146+ return cache_utility .EmptyCacheView ()
147+
145148 result = self ._dm_channel_entries
146- self ._dm_channel_entries = collections .FreezableDict ( )
149+ self ._dm_channel_entries = collections .LimitedCapacityCacheMap ( limit = self . _settings . max_dm_channel_ids )
147150 return cache_utility .CacheMappingView (result )
148151
149152 def delete_dm_channel_id (
150153 self , user : snowflakes .SnowflakeishOr [users .PartialUser ], /
151154 ) -> typing .Optional [snowflakes .Snowflake ]:
155+ if not self ._is_cache_enabled_for (config .CacheComponents .DM_CHANNEL_IDS ):
156+ return None
157+
152158 return self ._dm_channel_entries .pop (snowflakes .Snowflake (user ), None )
153159
154160 def get_dm_channel_id (
155161 self , user : snowflakes .SnowflakeishOr [users .PartialUser ], /
156162 ) -> typing .Optional [snowflakes .Snowflake ]:
163+ if not self ._is_cache_enabled_for (config .CacheComponents .DM_CHANNEL_IDS ):
164+ return None
165+
157166 return self ._dm_channel_entries .get (snowflakes .Snowflake (user ))
158167
159168 def get_dm_channel_ids_view (self ) -> cache .CacheView [snowflakes .Snowflake , snowflakes .Snowflake ]:
169+ if not self ._is_cache_enabled_for (config .CacheComponents .DM_CHANNEL_IDS ):
170+ return cache_utility .EmptyCacheView ()
171+
160172 return cache_utility .CacheMappingView (self ._dm_channel_entries .freeze ())
161173
162174 def set_dm_channel_id (
@@ -165,9 +177,10 @@ def set_dm_channel_id(
165177 channel : snowflakes .SnowflakeishOr [channels .PartialChannel ],
166178 / ,
167179 ) -> None :
168- user = snowflakes .Snowflake (user )
169- if self ._is_cache_enabled_for (config .CacheComponents .EMOJIS ) and user in self ._user_entries :
170- self ._dm_channel_entries [user ] = snowflakes .Snowflake (channel )
180+ if not self ._is_cache_enabled_for (config .CacheComponents .DM_CHANNEL_IDS ):
181+ return None
182+
183+ self ._dm_channel_entries [snowflakes .Snowflake (user )] = snowflakes .Snowflake (channel )
171184
172185 def _build_emoji (
173186 self ,
0 commit comments