Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support implementing a method on a class to make it hashable for caching #10348

@BartSchuurmans

Description

@BartSchuurmans

Checklist

  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.

Summary

@st.cache_data(hash_funcs=...) can be used to support hashing non-natively supported types as cache keys. However, this requires passing the hash_funcs parameter to every cache decorator.

I would like to be able to implement a method on my own types that Streamlit calls to make that type hashable.

This is technically already possible with __reduce__, but that can have unintended consequences: #6290 (comment)

Alternatively, I would like to be able to register my type once with a custom hashing function, by calling a function early during startup of the application, or by specifying it in a config file.

Why?

I use a (Pydantic) helper class throughout my Streamlit application that I would like to be able to hash to make intermediate functions cacheable.

How?

No response

Additional Context

A similar issue (#6290) was fixed by #6502, but this solution is quite verbose if you have many functions that receive your custom type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:cacheRelated to `st.cache_data` and `st.cache_resource`feature:cache-hash-funcRelated to cache hashing functionstype:enhancementRequests for feature enhancements or new features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions