Skip to content

Add method invalidate_cached_property for convenience #96

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cached_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,14 @@ def __get__(self, obj, cls):
# Alias to make threaded_cached_property_with_ttl easier to use
threaded_cached_property_ttl = threaded_cached_property_with_ttl
timed_threaded_cached_property = threaded_cached_property_with_ttl


def invalidate_cached_property(o, name):
"""
Invalidates the cached property so it will be re-computed again for the next access.

:param o: The object which property should be invalidated.
:param name: The property name to be invalidated.
"""
if hasattr(o, name):
delattr(o, name)