@@ -1852,14 +1852,6 @@ bounded by the specified *maxsize*. The disadvantage is that instances
1852
1852
are kept alive until they age out of the cache or until the cache is
1853
1853
cleared.
1854
1854
1855
- To avoid keeping an instance alive, it can be wrapped a weak reference
1856
- proxy. That allows an instance to be freed prior aging out of the LRU
1857
- cache. That said, the weak reference technique is rarely needed. It is
1858
- only helpful when the instances hold large amounts of data and the
1859
- normal aging-out process isn't fast enough. And even though the
1860
- instance is released early, the cache still keeps references to the
1861
- other method arguments and to the result of the method call.
1862
-
1863
1855
This example shows the various techniques::
1864
1856
1865
1857
class Weather:
@@ -1884,16 +1876,6 @@ This example shows the various techniques::
1884
1876
"Rainfall on a given date"
1885
1877
# Depends on the station_id, date, and units.
1886
1878
1887
- def climate(self, category='average_temperature'):
1888
- "List of daily average temperatures for a full year"
1889
- return self._climate(weakref.proxy(self), category)
1890
-
1891
- @staticmethod
1892
- @lru_cache(maxsize=10)
1893
- def _climate(self_proxy, category):
1894
- # Depends on a weak reference to the instance
1895
- # and on the category parameter.
1896
-
1897
1879
The above example assumes that the *station_id * never changes. If the
1898
1880
relevant instance attributes are mutable, the *cached_property * approach
1899
1881
can't be made to work because it cannot detect changes to the
0 commit comments