python-synthetica 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_synthetica-0.1.0.dist-info/LICENSE +28 -0
- python_synthetica-0.1.0.dist-info/METADATA +154 -0
- python_synthetica-0.1.0.dist-info/RECORD +10 -0
- python_synthetica-0.1.0.dist-info/WHEEL +4 -0
- synthetica/__init__.py +1 -0
- synthetica/base.py +325 -0
- synthetica/config.py +144 -0
- synthetica/decorators.py +23 -0
- synthetica/models.py +1170 -0
- synthetica/stats.py +92 -0
synthetica/decorators.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def callback(cache_name):
|
|
5
|
+
def decorator(setter_func):
|
|
6
|
+
@wraps(setter_func)
|
|
7
|
+
def wrapper(self, new_value, *args, **kwargs):
|
|
8
|
+
# Get the current value of the property
|
|
9
|
+
prop_name = setter_func.__name__
|
|
10
|
+
current_value = getattr(self, f"_{prop_name}")
|
|
11
|
+
|
|
12
|
+
# Call the original setter function
|
|
13
|
+
result = setter_func(self, new_value, *args, **kwargs)
|
|
14
|
+
|
|
15
|
+
# If the value has changed, invalidate the cache
|
|
16
|
+
if current_value != new_value:
|
|
17
|
+
self.__dict__.pop(cache_name, None)
|
|
18
|
+
|
|
19
|
+
return result
|
|
20
|
+
|
|
21
|
+
return wrapper
|
|
22
|
+
|
|
23
|
+
return decorator
|