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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for computed_cached_property-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b4922cb9e15c3a64a02180b85aa8e509d27c99fc6efc61d15736679536c8b9e |
|
MD5 | 0d8b51e642f5b0a6f14fc6a9d36ea0b7 |
|
BLAKE2b-256 | bf9d980e8a10656eeb502b8ad4cffa486b36a09f4ff0e959a654507cc34552f9 |