【发布时间】:2021-09-06 11:54:12
【问题描述】:
这可能比我想象的要简单,但我想将令牌或类似字符串存储大约 24 小时,24 小时后,我希望存储的令牌或存储的字符串过期或没有价值。
# Function I currently have, it does not store the token and does not expire after 24 hours
import streamlit as st
def check_token(token_provided):
strip_words = "ab 1jd9k1la0 "
no_token = ""
if strip_words in token_provided:
new_token = token_provided.replace(strip_words,"")
else:
new_token = token_provided
token = new_token
return token
另外,令牌存储后,如何检查用户是否输入了正确的令牌值。
我目前正在使用 streamlit,但我不确定 Session.state 是否可行。
【问题讨论】:
-
您需要使用某种缓存机制,或者使用 Redis 之类的缓存框架,或者您需要让脚本以“无限”状态运行,以保持变量的值内存无限期(不过我不推荐这种方法)。
-
感谢您的洞察力。我会研究一下。