Beispiel #1
0
 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")
Beispiel #2
0
 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))
                 }
             })
Beispiel #3
0
 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")