Add caching capabilities for hybrid attributes

Issue #3678 wontfix
David Baumgold created an issue

It's often useful to have cached properties, especially for computationally expensive properties. Werkzeug has a @cached_property decorator that works very nicely for this, but it can't be used directly with @hybrid_property. Could a feature be added to SQLAlchemy's hybrid attributes to allow automatic per-instance caching?

Comments (2)

  1. Mike Bayer repo owner

    perhaps this is something sqlalchemy_utils or similar provides ? caching is a controversial subject so I like to keep this out of SQLAlchemy itself, there's enough features to maintain. SQLA's own recommendation is to use Dogpile Caching (also mine) which has a cache decorator.

    also im not sure how caching would interact with a hybrid property at the class level.

  2. Log in to comment