Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve in-memory cache #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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