What is the difference between @property and @cached_property in a Django model?
Last updated
@propertyrecomputes the method on every access, so it always reflects current field values (good for cheap computations).@cached_property(fromdjango.utils.functional) computes once per instance and stores the result, ideal for expensive work like DB queries accessed repeatedly.Caveat: the cached value can go stale if data changes during the instance's life. Clear it with
del obj.attr.
- https://www.geeksforgeeks.org/python/django-interview-questions/
- https://foysalff.medium.com/12-advanced-django-interview-questions-for-experienced-developers-dbe654e21a45
- https://www.careers360.com/courses-certifications/articles/django-interview-questions-and-answers
- https://www.interviewbit.com/django-interview-questions/
- https://www.youtube.com/watch?v=OuBUUkQfBYM
- https://www.placementpreparation.io/blog/django-interview-questions-for-freshers/