2021-01-07 22:01:49 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
|
|
|
import sys
|
|
|
|
sys.path.append('../..')
|
|
|
|
import report
|
2024-09-15 18:58:42 +02:00
|
|
|
import caching
|
|
|
|
import time
|
2021-01-07 22:01:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
report.stdoutLoggingConfigure(log_name_lvl=[('root', 'DEBUG'), ])
|
|
|
|
|
|
|
|
|
|
|
|
class test_slow_data(object):
|
2024-09-15 18:58:42 +02:00
|
|
|
DATA_VERSION = 0.1
|
|
|
|
KEY_ONE = '1'
|
|
|
|
KEY_TWO = '2'
|
|
|
|
KEY_THREE = 'three'
|
|
|
|
KEY_FOUR = 'four'
|
|
|
|
KEY_FIVE = 'five'
|
|
|
|
KEYS = [KEY_ONE, KEY_TWO, KEY_THREE, KEY_FOUR, KEY_FIVE]
|
2021-01-07 22:01:49 +01:00
|
|
|
|
|
|
|
def data_version(self):
|
2024-09-15 18:58:42 +02:00
|
|
|
return self.DATA_VERSION
|
2021-01-07 22:01:49 +01:00
|
|
|
|
|
|
|
def get(self, key, default=None):
|
2024-09-15 18:58:42 +02:00
|
|
|
try:
|
|
|
|
return getattr(self, f'__{key}__')()
|
|
|
|
except AttributeError:
|
|
|
|
return default
|
2021-01-07 22:01:49 +01:00
|
|
|
|
|
|
|
def keys(self):
|
|
|
|
return self.KEYS
|
|
|
|
|
|
|
|
def uid(self):
|
|
|
|
return None
|
|
|
|
|
2024-09-15 18:58:42 +02:00
|
|
|
def print_n_sleep(self, k):
|
|
|
|
sys.stdout.write('slow get executed for %s\n' % k)
|
|
|
|
time.sleep(3)
|
2021-01-07 22:01:49 +01:00
|
|
|
|
2024-09-15 18:58:42 +02:00
|
|
|
def __1__(self):
|
|
|
|
self.print_n_sleep("__1__")
|
|
|
|
return 'one'
|
2021-01-07 22:01:49 +01:00
|
|
|
|
2024-09-15 18:58:42 +02:00
|
|
|
def __2__(self):
|
|
|
|
self.print_n_sleep("__2__")
|
|
|
|
return 'two'
|
|
|
|
|
|
|
|
def __three__(self):
|
|
|
|
self.print_n_sleep("__three__")
|
|
|
|
return 'three'
|
|
|
|
|
|
|
|
def __four__(self):
|
|
|
|
self.print_n_sleep("__four__")
|
|
|
|
return 'four'
|
|
|
|
|
|
|
|
def __five__(self):
|
|
|
|
self.print_n_sleep("__five__")
|
|
|
|
return 'five'
|
2021-01-07 22:01:49 +01:00
|
|
|
|
|
|
|
|
2024-09-15 18:58:42 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
data = caching.property_cache_pickle(test_slow_data(), 'cache.pickle')
|
|
|
|
data.add_source_get_keys(data.KEY_THREE)
|
|
|
|
print('Testing property_cache (pickle):\\n--------------------------------')
|
|
|
|
for key in data.keys():
|
|
|
|
print(data.get(key))
|
2021-01-07 22:01:49 +01:00
|
|
|
|