A decorator for caching computed properties in classes. like Vue's Computed-Properties
Project description
computed-cached-property
A decorator for caching computed properties in classes. like Vue's Computed-Properties
install
pip install computed-cached-property
example
from computed_cached_property import computed_cached_property
from dataclasses import dataclass
@dataclass
class A:
v1: int = 1
v2: str = 'fuck'
v3: bool = False
@property
@computed_cached_property
def v4(self):
print('run code in v4 function')
return f'v1:{self.v1}, v2:{self.v2}, v3:{self.v3}'
@property
@computed_cached_property(typed=Ture)
# same as @functools.lru_cache(maxsize=1, typed=Ture)
def v5(self):
print('run code in v4 function')
return f'v1:{self.v1}, v2:{self.v2}, v3:{self.v3}'
a1 = A(v1=99)
print(a1.v4)
print(a1.v4)
a1.v2 = 'xxoo'
print(a1.v4)
# output
# run code in v4 function
# v1:99, v2:fuck, v3:False
# v1:99, v2:fuck, v3:False
# run code in v4 function
# v1:99, v2:xxoo, v3:False
Hint
Not recommended for use in a production environment
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for computed-cached-property-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ecd0fd59948b076f2d826b3848f6d3a9e3c9eecc5c6963dc7a69e0d2ff13efc |
|
MD5 | 7a3e265b6fe9b920dddc3097a12acb7e |
|
BLAKE2b-256 | 31eaf7beefa69f07f0415f3eab40c7cc3c6066bd7f2fb8b1da2c115b2e435fa4 |
Close
Hashes for computed_cached_property-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55acd8d011d6473f810fedfac630f593d4ea35f6037348b2e0c0af931096259c |
|
MD5 | 6ae7c72171a41ccc0a3a7017b5f5d8e8 |
|
BLAKE2b-256 | 6cdcb61f5cd54d64029636ec938be5637bf78e4b5aa59e1fb9f28f649a19659f |