0

Added expiration of uuidcache entries

Entries in the uuidcache will now be considered expired if they were
retrieved before the mtime of the player dat file. This follows the
recommendation made in issue #1279.
This commit is contained in:
3decibels
2017-06-04 23:43:28 +00:00
parent 412c8231b7
commit e5b90fd512

View File

@@ -258,13 +258,15 @@ class PlayerDict(dict):
sname = self._name.replace('-','') sname = self._name.replace('-','')
try: try:
profile = PlayerDict.uuid_cache[sname] profile = PlayerDict.uuid_cache[sname]
return profile['name'] if profile['retrievedAt'] > time.mktime(self['time']):
return profile['name']
except (KeyError,): except (KeyError,):
pass pass
try: try:
profile = json.loads(urllib2.urlopen(UUID_LOOKUP_URL + sname).read()) profile = json.loads(urllib2.urlopen(UUID_LOOKUP_URL + sname).read())
if 'name' in profile: if 'name' in profile:
profile['retrievedAt'] = time.mktime(time.localtime())
PlayerDict.uuid_cache[sname] = profile PlayerDict.uuid_cache[sname] = profile
return profile['name'] return profile['name']
except (ValueError, urllib2.URLError): except (ValueError, urllib2.URLError):