Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st.cache doesn't invalidate when internal function changes #2728

Closed
vdonato opened this issue Feb 4, 2021 · 2 comments
Closed

st.cache doesn't invalidate when internal function changes #2728

vdonato opened this issue Feb 4, 2021 · 2 comments
Labels
feature:cache Related to st.cache_data and st.cache_resource type:bug Something isn't working

Comments

@vdonato
Copy link
Collaborator

vdonato commented Feb 4, 2021

(via @tvst)

Steps to repro:

  1. Run this:
@st.cache
def cached_function():
    return get_number()

def get_number():
    def internal_get_number():
        return 42

    return internal_get_number()


st.write(cached_function())  # Displays 42
  1. Now modify the file this way and press "r" to rerun:
@st.cache
def cached_function():
    return get_number()

def get_number():
    def internal_get_number():
        return 100000000000

    return internal_get_number()


st.write(cached_function())  # Still displays 42!!!!

This still displays 42, even though it should display 100000000000

  1. Now clear your cache by pressing "c" and rerun with "r":

Now you see 100000000000. Yay!

@vdonato vdonato added type:bug Something isn't working feature:cache Related to st.cache_data and st.cache_resource labels Feb 4, 2021
@ktosiek
Copy link
Contributor

ktosiek commented Feb 16, 2021

It looks like it only breaks if the changed function is after the dependency, and even breaks without nested functions:

import streamlit as st

@st.cache
def cached_function():
    return number

number = 42

st.write(cached_function())  # Displays 42, even after changing `number`

Nested functions work if you define the functions in "dependency order":

import streamlit as st

def get_number():
    def internal_get_number():
        return 42

    return internal_get_number()

@st.cache
def cached_function():
    return get_number()

st.write(cached_function())

@kmcgrady
Copy link
Collaborator

PR has been merged, so I will close this issue. This should be fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:cache Related to st.cache_data and st.cache_resource type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants