mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-10-12 09:10:45 +00:00
Add FlaskSessionCacheHandler (#833)
Updated examples/app.py Updated CHANGELOG.md and appropriate docs.
This commit is contained in:
1 parent
7337bf9352
commit
7fc08809f0
4 files changed
+40
-26
No files matched your search
@@ -2,6 +2,7 @@ __all__ = [
|
||||
'CacheHandler',
|
||||
'CacheFileHandler',
|
||||
'DjangoSessionCacheHandler',
|
||||
'FlaskSessionCacheHandler',
|
||||
'MemoryCacheHandler',
|
||||
'RedisCacheHandler']
|
||||
|
||||
@@ -147,6 +148,31 @@ class DjangoSessionCacheHandler(CacheHandler):
|
||||
logger.warning("Error saving token to cache: " + str(e))
|
||||
|
||||
|
||||
class FlaskSessionCacheHandler(CacheHandler):
|
||||
"""
|
||||
A cache handler that stores the token info in the session framework
|
||||
provided by flask.
|
||||
"""
|
||||
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
|
||||
def get_cached_token(self):
|
||||
token_info = None
|
||||
try:
|
||||
token_info = self.session["token_info"]
|
||||
except KeyError:
|
||||
logger.debug("Token not found in the session")
|
||||
|
||||
return token_info
|
||||
|
||||
def save_token_to_cache(self, token_info):
|
||||
try:
|
||||
self.session["token_info"] = token_info
|
||||
except Exception as e:
|
||||
logger.warning("Error saving token to cache: " + str(e))
|
||||
|
||||
|
||||
class RedisCacheHandler(CacheHandler):
|
||||
"""
|
||||
A cache handler that stores the token info in the Redis.
|
||||
|
||||
Reference in new issue
Block a user