Laid groundwork for displaying avatar images
This commit is contained in:
parent
0c280eeb4d
commit
522a522129
3 changed files with 55 additions and 5 deletions
40
avcache.py
Normal file
40
avcache.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from threading import RLock
|
||||
|
||||
|
||||
class AvCache:
|
||||
"""
|
||||
Store a cache of avatar images we've already downloaded.
|
||||
This cache will be accessed by a number of threads, so it includes
|
||||
a lock as well.
|
||||
"""
|
||||
|
||||
class __impl:
|
||||
""" Implementation of the singleton interface """
|
||||
|
||||
def __init__(self):
|
||||
self.lock = RLock()
|
||||
self.map = {}
|
||||
|
||||
|
||||
# storage for the instance reference
|
||||
__instance = None
|
||||
|
||||
def __init__(self):
|
||||
""" Create singleton instance """
|
||||
# Check whether we already have an instance
|
||||
if AvCache.__instance is None:
|
||||
# Create and remember instance
|
||||
AvCache.__instance = AvCache.__impl()
|
||||
|
||||
# Store instance reference as the only member in the handle
|
||||
self.__dict__['_AvCache__instance'] = AvCache.__instance
|
||||
|
||||
def __getattr__(self, attr):
|
||||
""" Delegate access to implementation """
|
||||
return getattr(self.__instance, attr)
|
||||
|
||||
def __setattr__(self, attr, value):
|
||||
""" Delegate access to implementation """
|
||||
return setattr(self.__instance, attr, value)
|
||||
|
||||
# end class AvCache
|
Reference in a new issue