Ticket #8510: t8510-Configuration-cache-r8720.diff
| File t8510-Configuration-cache-r8720.diff, 2.5 KB (added by cboos, 3 years ago) |
|---|
-
trac/config.py
28 28 29 29 _TRUE_VALUES = ('yes', 'true', 'enabled', 'on', 'aye', '1', 1, True) 30 30 31 _use_default = object() 32 31 33 def _to_utf8(basestr): 32 34 return to_unicode(basestr).encode('utf-8') 33 35 … … 53 55 self._lastmtime = 0 54 56 self._sections = {} 55 57 self.parse_if_needed() 58 self._cache = {} 56 59 57 60 def __contains__(self, name): 58 61 """Return whether the configuration contains a section of the given … … 237 240 changed = False 238 241 modtime = os.path.getmtime(self.filename) 239 242 if modtime > self._lastmtime: 243 self._cache = {} 240 244 self.parser._sections = {} 241 245 self.parser.read(self.filename) 242 246 self._lastmtime = modtime … … 311 315 312 316 Valid default input is a string. Returns a string. 313 317 """ 318 ckey = (self.name, key) 319 cached = self.config._cache.get(ckey, _use_default) 320 if cached is not _use_default: 321 return cached 314 322 name_str = _to_utf8(self.name) 315 323 key_str = _to_utf8(key) 316 324 if self.config.parser.has_option(name_str, key_str): … … 318 326 elif self.config.parent: 319 327 value = self.config.parent[self.name].get(key, default) 320 328 else: 321 option = Option.registry.get( (self.name, key))329 option = Option.registry.get(ckey) 322 330 if option: 323 value = option.default or default331 value = option.default or _use_default 324 332 else: 325 value = default 333 value = _use_default 334 if value is _use_default: 335 return default 326 336 if not value: 327 returnu''337 value = u'' 328 338 elif isinstance(value, basestring): 329 returnto_unicode(value)330 else:331 return value339 value = to_unicode(value) 340 self.config._cache[ckey] = value 341 return value 332 342 333 343 def getbool(self, key, default=''): 334 344 """Return the value of the specified option as boolean. … … 418 428 419 429 These changes are not persistent unless saved with `save()`. 420 430 """ 431 self.config._cache.pop((self.name, key), None) 421 432 name_str = _to_utf8(self.name) 422 433 key_str = _to_utf8(key) 423 434 if not self.config.parser.has_section(name_str):
