Skip to content

Commit

Permalink
add documentation for tab storage
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Dec 15, 2024
1 parent 8acae80 commit a387927
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nicegui/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
16 changes: 16 additions & 0 deletions website/documentation/content/storage_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit a387927

Please sign in to comment.