awacke1's picture
Create app.py
f630872 verified
raw
history blame
1.1 kB
import streamlit as st
from datetime import timedelta
# Function to cache user data
@st.cache_resource(ttl=timedelta(days=1), max_entries=10, show_spinner=True)
def cache_user_data(email, phone, password):
return {'email': email, 'phone': phone, 'password': password}
# Main app function
def main():
st.title('User Data Caching Example')
# Retrieve cached data if it exists
cached_data = cache_user_data("", "", "")
email, phone, password = cached_data['email'], cached_data['phone'], cached_data['password']
# Input fields with emojis
new_email = st.text_input("πŸ“§ Email Address", value=email)
new_phone = st.text_input("πŸ“± Mobile Phone", value=phone)
new_password = st.text_input("πŸ”‘ Password", value=password, type='password')
# Update cache if data changes
if new_email != email or new_phone != phone or new_password != password:
cache_user_data(new_email, new_phone, new_password)
st.success("Data updated and cached!")
st.write("Cached Data:")
st.json(cached_data)
# Run the app
if __name__ == "__main__":
main()