implement 'update()' for caches

pull/133/head
Mike Fährmann 6 years ago
parent d8492df51b
commit 2221cf97ff
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2017 Mike Fährmann
# Copyright 2016-2018 Mike Fährmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
@ -187,12 +187,14 @@ class CacheDecorator():
return functools.partial(self.__call__, obj)
def invalidate(self, key=None):
if key is None:
key = self.key
else:
key = "%s-%s" % (self.key, key)
key = "%s-%s" % (self.key, key) if key else self.key
del self.cache[key]
def update(self, key, result):
key = "%s-%s" % (self.key, key) if key else self.key
expires = int(time.time() + self.maxage)
self.cache[key] = result, expires
def build_cache_decorator(*modules):
if len(modules) > 1:

@ -577,8 +577,7 @@ class DeviantartAPI():
raise exception.AuthenticationError('"{} ({})"'.format(
data.get("error_description"), data.get("error")))
if refresh_token:
_refresh_token_cache.invalidate(refresh_token)
_refresh_token_cache(refresh_token, data["refresh_token"])
_refresh_token_cache.update(refresh_token, data["refresh_token"])
return "Bearer " + data["access_token"]
def _call(self, endpoint, params=None, expect_error=False, public=True):

Loading…
Cancel
Save