Revert cached_property_with_ttl/threaded_cached_property_with_ttl to settable just...
authorGeorge Sakkis <george.sakkis@gmail.com>
Tue, 21 Apr 2015 00:21:36 +0000 (03:21 +0300)
committerGeorge Sakkis <george.sakkis@gmail.com>
Tue, 21 Apr 2015 00:21:36 +0000 (03:21 +0300)
cached_property.py
tests/test_cached_property.py

index 45654b8d1ca5648d8e2791094ec38d2fad4bb618..ee896aec39fe8425fb055d3e9614b0b9e4a67985 100644 (file)
@@ -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:
index 725a87ebc4ad5ea2c042235a3de2676ed635aa9b..1bca7ab215604b2c063ac0883ba79719f65780a2 100644 (file)
@@ -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()