0
我們使用mongodb,並通過pymongo訪問。訪問具有大約1000行的域表的方法更好。注意:findCat將在循環中被調用10,000次?pymongo - 哪種方法更有效率 - 找到一個vs找到一個?
緩存到字典
def __init__(self):
self.categories_dict=Utils.todict(db.collection.find_all)
def findCat(self, key):
return self.categories_dict(key)
或 直接查詢
def findCat(key):
#return object for the key
return db.collection.find_one