Inspect and / or delete cached properties #211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @pydanny,
Thank you for this package! This pull request addresses issues #32 and #196. Here is a sum-up:
CachedProperty
, so that we can useisinstance
to identify them easily.cached_properties
: iterate over the cached properties of an object.is_cached
: whether a cached property is already cached.un_cache
: empty the cache for a cached property. As @Tinche noted, it avoids exposing an implementation detail.delete_cache
: empty the whole cache of an object.property_deleting_cache
: a property that deletes the cache when it is set or deleted. A typical example of application is given in the docstring (and in the readme).For
property_deleting_cache
, some people may find it strange to have this parameterfunc
whose output is ignored. As a matter of fact, in most use cases, I guess that its code will bepass
. I hesitated a bit and I also implemented another syntax option inproperty_deleting_cache_2
. However, I still prefer option 1 because its usage as a decorator is more similar to what we use for regular properties and cached properties. Tell me which one you prefer (and just remove the other one)!In the readme, I suggest replacing the running example about monopoly by a more generic example. This monopoly example seemed quite unnatural to me, and I hope that the new one is more telling, even if it is a bit less funny.
This is my first pull request ever so do not hesitate to tell me if I did something wrong :-). Best,
François