Add FlaskSessionCacheHandler (#833)

Updated examples/app.py
Updated CHANGELOG.md and appropriate docs.
This commit is contained in:
Bryan Malyn authored and GitHub committed 2022-06-25 20:00:08 +01:00
1 parent 7337bf9352
commit 7fc08809f0
4 files changed
+40 -26

No files matched your search

+26
View File
@@ -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.