How to use with singleton?
allran opened this issue · 1 comments
allran commented
class SingletonClass(object):
"""
单例模式--类装饰器
example:
@SingletonClass
class A:
a=1
def __init__(self,x=0):
self.x=x
"""
def __init__(self, cls):
self.cls = cls
self.instance = {}
def __call__(self):
if self.cls not in self.instance:
print("Created new instance")
self.instance[self.cls] = self.cls()
return self.instance[self.cls]
s1 = Cache(maxsize=1024)
s2 = Cache(maxsize=1024)
Any way to use cache in singleton, I mean s2 is s1.
tkem commented
Please use GitHub issues only for bug reports, for now.
Feature requests will not be accepted at this time, and general questions, like yours seems to be, should probably be posted at stackoverflow. It's more likely you'll get an answer there.