diff --git a/nicegui/storage.py b/nicegui/storage.py index 8e7376728..1456569f0 100644 --- a/nicegui/storage.py +++ b/nicegui/storage.py @@ -53,7 +53,8 @@ class Storage: def __init__(self) -> None: self.path = Path(os.environ.get('NICEGUI_STORAGE_PATH', '.nicegui')).resolve() - self.max_tab_storage_age = timedelta(days=30).total_seconds() + self.max_tab_storage_age: float = timedelta(days=30).total_seconds() + """Maximum age in seconds before tab storage is automatically purged. Defaults to 30 days.""" self._general = RedisPersistentDict() # PersistentDict(self.path / 'storage-general.json', encoding='utf-8') self._users: Dict[str, FilePersistentDict] = {} self._tabs: Dict[str, observables.ObservableDict] = {} diff --git a/website/documentation/content/storage_documentation.py b/website/documentation/content/storage_documentation.py index 9a29faae1..76574e110 100644 --- a/website/documentation/content/storage_documentation.py +++ b/website/documentation/content/storage_documentation.py @@ -132,6 +132,22 @@ def tab_storage(): ui.button('Reload page', on_click=ui.navigate.reload) +@doc.demo('Maximum age of tab storage', ''' + By default, the tab storage is kept for 30 days. + You can change this by setting `app.storage.max_tab_storage_age`. +''') +def max_tab_storage_age(): + from nicegui import app + from datetime import timedelta + # app.storage.max_tab_storage_age = timedelta(minutes=1).total_seconds() + ui.label(f'Tab storage age: {timedelta(minutes=1).total_seconds()} seconds') # HIDE + + @ui.page('/') + def index(): + # ui.label(f'Tab storage age: {app.storage.tab.age} seconds') + pass # HIDE + + @doc.demo('Short-term memory', ''' The goal of `app.storage.client` is to store data only for the duration of the current page visit. In difference to data stored in `app.storage.tab`