Trouble in using cache


I want my code to refresh cache.

Steps to reproduce

Code snippet:

import streamlit as st
import os, shutil
from myimage import myimage
from blur import blur_image

def get_jpg(_image : myimage):
    _image.get_png()        # Call API and download according to the It is saved as 'tmp/image.png'.
    _image.convert()        # Convert 'tmp/image.png' to 'tmp/image.jpg' and save it.

if "btn_clicked" not in st.session_state:
    st.session_state.btn_clicked = False

def callback():
    st.session_state.btn_clicked = True

image_id = st.number_input('image_id')

get_image_button = st.button('Get Image', on_click = callback)

if get_image_button or st.session_state.btn_clicked:
    image = myimage(image_id) # Instance
    if st.button('Blur'):
        blur_image('tmp/image.jpg')     # Generate bluured input image and save as 'blur.jpg'

        with open('blur.jpg', 'rb') as file:
            if st.download_button('Download', data = file, file_name = 'image.jpg'):

Expected behavior:

Whenever I enter the image_id, I should get blurred image.
Also, it should be okay when many people use this app together.

Actual behavior:

It doesn’t make any error for the first time.
However, if I put different image_id, it makes error with

FileNotFoundError: [Errno 2] No such file or directory: 'tmp/image.png'

I tried to use hash_function in the decorator, but as far as I know, it can handle only properties, not methods.

I can run your code without errors. You must be doing something different.