cache requirements, not features, for even better results
This commit is contained in:
parent
0435225a29
commit
a856c27fe4
@ -102,12 +102,7 @@ class FeatureDetector(object):
|
|||||||
return {name: feature_details(name) for name in FeatureDetector.features}
|
return {name: feature_details(name) for name in FeatureDetector.features}
|
||||||
|
|
||||||
def is_available(self, feature):
|
def is_available(self, feature):
|
||||||
cache = FeatureCache.getSharedInstance()
|
return self.has_requirements(self.get_requirements(feature))
|
||||||
if cache.has(feature):
|
|
||||||
return cache.get(feature)
|
|
||||||
result = self.has_requirements(self.get_requirements(feature))
|
|
||||||
cache.set(feature, result)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def get_requirements(self, feature):
|
def get_requirements(self, feature):
|
||||||
try:
|
try:
|
||||||
@ -128,12 +123,19 @@ class FeatureDetector(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def has_requirement(self, requirement):
|
def has_requirement(self, requirement):
|
||||||
|
cache = FeatureCache.getSharedInstance()
|
||||||
|
if cache.has(requirement):
|
||||||
|
return cache.get(requirement)
|
||||||
|
|
||||||
method = self._get_requirement_method(requirement)
|
method = self._get_requirement_method(requirement)
|
||||||
|
result = False
|
||||||
if method is not None:
|
if method is not None:
|
||||||
return method()
|
result = method()
|
||||||
else:
|
else:
|
||||||
logger.error("detection of requirement {0} not implement. please fix in code!".format(requirement))
|
logger.error("detection of requirement {0} not implement. please fix in code!".format(requirement))
|
||||||
return False
|
|
||||||
|
cache.set(requirement, result)
|
||||||
|
return result
|
||||||
|
|
||||||
def get_requirement_description(self, requirement):
|
def get_requirement_description(self, requirement):
|
||||||
return inspect.getdoc(self._get_requirement_method(requirement))
|
return inspect.getdoc(self._get_requirement_method(requirement))
|
||||||
|
Loading…
Reference in New Issue
Block a user