From: George Sakkis Date: Tue, 21 Apr 2015 00:21:36 +0000 (+0300) Subject: Revert cached_property_with_ttl/threaded_cached_property_with_ttl to settable just... X-Git-Tag: 1.2.0~5^2~1 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=59a6292eb2f7a2b4e0c2f2534d14b48a13c4fe2d;p=cached-property.git Revert cached_property_with_ttl/threaded_cached_property_with_ttl to settable just like cached_property/threaded_cached_property --- diff --git a/cached_property.py b/cached_property.py index 45654b8..ee896ae 100644 --- a/cached_property.py +++ b/cached_property.py @@ -96,6 +96,9 @@ class cached_property_with_ttl(object): def __delete__(self, obj): obj.__dict__.pop(self.__name__, None) + def __set__(self, obj, value): + obj.__dict__[self.__name__] = (value, time()) + def _prepare_func(self, func): self.func = func if func: diff --git a/tests/test_cached_property.py b/tests/test_cached_property.py index 725a87e..1bca7ab 100644 --- a/tests/test_cached_property.py +++ b/tests/test_cached_property.py @@ -116,6 +116,13 @@ class TestCachedProperty(unittest.TestCase): self.assert_cached(Check(), None) + def test_set_cached_property(self): + Check = CheckFactory(self.cached_property_factory) + check = Check() + check.add_cached = 'foo' + self.assertEqual(check.add_cached, 'foo') + self.assertEqual(check.cached_total, 0) + def test_threads(self): Check = CheckFactory(self.cached_property_factory, threadsafe=True) check = Check()