From bf0dba037a90c66f5b612d146079954349f8d2c9 Mon Sep 17 00:00:00 2001 From: "Bruno D. Rodrigues" Date: Sat, 16 Mar 2024 14:15:25 +0000 Subject: [PATCH] Improve in-memory cache by using the itunes_server or apple_id as the key; fixes #42 --- main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index f6e9ebf..0817dbe 100755 --- a/main.py +++ b/main.py @@ -228,11 +228,12 @@ def handleLookup(self, args): storeClientCache = {} def _get_StoreClient(self, args): - for k, v in self.storeClientCache.items(): - if time.time() - v < 30.0: - return k - else: - del self.storeClientCache[k] + cachekey = args.itunes_server or args.appleid + store, lastseen = self.storeClientCache.get(cachekey, (None, None,)) + if store: + if time.time() - lastseen < 30.0: + return store + del self.storeClientCache[cachekey] newSess = pickle.loads(pickle.dumps(self.sess)) Store = StoreClient(newSess) @@ -313,7 +314,7 @@ def authedPost(*args, **kwargs): Store.sess.original_post = Store.sess.post Store.sess.post = authedPost - self.storeClientCache[Store] = time.time() + self.storeClientCache[cachekey] = (Store, time.time(),) return Store def _handleStoreException(self, _e):