def insert(self, *cache: Cache): if cache.__len__() == 1: self.db_connection.insert(self.collection, cache[0].to_dict()) elif cache.__len__() > 1: self.db_connection.insert_many( self.collection, list(map(lambda this_cache: this_cache.to_dict(), cache))) else: print("CacheDao#insert: Nothing to insert")
def delete(self, *cache: Cache): if cache.__len__() == 1: self.db_connection.delete_one(self.collection, { "is_valid": cache[0].is_valid, "timestamp": cache[0].timestamp }) elif cache.__len__() > 1: self.db_connection.delete_many( self.collection, { 'timestamp': { "$set": list( map(lambda this_cache: this_cache.timestamp, cache)) } })
def update(self, *cache: Cache): if cache.__len__() == 1: self.db_connection.find_and_update( self.collection, {'timestamp': cache[0].timestamp}, {"$set": cache[0].to_dict()}) elif cache.__len__() > 1: self.db_connection.update_many( self.collection, { 'timestamp': { "$set": list( map(lambda this_cache: this_cache.timestamp, cache)) } }) else: print("CacheDao#update: Nothing to update")