Finding a path forward for `functools.cached_property`

Flask’s locked cached property technically has this issue, but it’s mitigated somewhat by the fact that there’s typically only one app instance, not many. Additionally, WSGI workers are commonly separate processes, where a lock doesn’t affect other requests. That said, I’ve thought before about removing it, and I should go look again because it’s probably unnecessary.

The reason Werkzeug implements its own (non-locked) cached property is because functools.cached_property didn’t exist. It also has some features that functools does not:

  • __set__ to update the value directly
  • __del__ to reset the cache so it’s computed again
  • Doesn’t require __dict__, classes that use __slots__ can add a special _cache_{name} slot for each property.
  • Is a subclass of property, and also generically typed, so it plays nice with typing.