cache when a setting isn't set but don't cache "default" value

This commit is contained in:
jesopo 2019-09-04 15:26:36 +01:00
parent 473c2723e7
commit d7ae182428

View file

@ -152,14 +152,16 @@ class Channel(IRCObject.Object):
def get_setting(self, setting: str, default: typing.Any=None
) -> typing.Any:
cache_key = self._setting_cache_key(setting)
value = None
if self.bot.cache.has_item(cache_key):
return self.bot.cache.get(cache_key)
value = self.bot.cache.get(cache_key)
else:
value = self.bot.database.channel_settings.get(self.id, setting, None)
self._cache_setting(cache_key, value)
value = self.bot.database.channel_settings.get(self.id, setting, None)
if value == None:
return default
else:
self._cache_setting(cache_key, value)
return value
def find_settings(self, pattern: str, default: typing.Any=[]