File size: 1,104 Bytes
f630872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()