@st.cache(allow_output_mutation=True, hash_funcs={"_thread.RLock": lambda _: None, "builtins.weakref":lambda _: None}, suppress_st_warning=True)
def loaddb():
    DB_DATA = dbconn()
    return  DB_DATA

DB_DATA = loaddb()

I fixed this problem using the above code.
the function loaddb() is just an intermediary function to assign the DB connection to a variable. We could have done it this way:
DB_DATA = dbconn()

but in order to cache the stuff we needed to convert this particular process in the form of a function.