Skip to content

Commit

Permalink
Improve in-memory cache by using the itunes_server or apple_id as the…
Browse files Browse the repository at this point in the history
… key; fixes NyaMisty#42
  • Loading branch information
davipt committed Mar 16, 2024
1 parent abfdb3a commit bf0dba0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit bf0dba0

Please sign in to comment.