Made cached ttl configurable (#546)

This commit is contained in:
Philipp Horstenkamp 2024-01-10 20:08:59 +01:00 committed by GitHub
commit 26292a9dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 9 deletions

View File

@ -16,11 +16,12 @@ Natürlich kann auch hier eine wie in der [README.md](../../../../README.md) gez
|:--------------------------:|:-------:|:---------------------:|---------------------------------------------------------------------------------------|
| HTTP_PORT | 80 | *Fehler* | Der Port auf dem die Applikation gestartet werden soll. |
| DASH_URL_BASE_PATHNAME | / | /transparenzregister/ | Der Basispfad auf dem HTTP-Requests empfangen werden. |
| PYTHON_DASH_LOGIN_USERNAME | | | Ein HTTP-Basic-Auth Username, kein Passwortschutz wenn leer. |
| PYTHON_DASH_LOGIN_PW | | | Ein HTTP-Basic-Auth Password, kein Passwortschutz wenn leer. |
| PYTHON_DASH_LOGIN_USERNAME | | | Ein HTTP-Basic-Auth Username, kein Passwortschutz wenn leer. |
| PYTHON_DASH_LOGIN_PW | | | Ein HTTP-Basic-Auth Password, kein Passwortschutz wenn leer. |
| PYTHON_POSTGRES_USERNAME | | postgres | Ein Nutzername für Zugriff auf die Production DB (Postgres) |
| PYTHON_POSTGRES_PASSWORD | | *Fehler* | Ein Passwort für Zugriff auf die Production DB (Postgres) |
| PYTHON_POSTGRES_HOST | | postgres | Der Host auf dem die Production DB (Postgres) erreichbar ist. |
| PYTHON_POSTGRES_DATABASE | | db | Der Name der Production DB (Postgres). |
| PYTHON_POSTGRES_PORT | | 5432 | Der Port auf dem auf die Prodction DB (Postgres) Zugegriffen werden kann. |
| PYTHON_POSTGRES_PORT | | 5432 | Der Port auf dem auf die Production DB (Postgres) Zugegriffen werden kann. |
| PYTHON_SQLITE_PATH | | | Ein Pfad um auf eine SQLLite Datenbank zuzugreifen. Überschreibt den Postgres Zugang. |
| PYTHON_CACHE_TTL | 3600 | | Defines how long the ttl cache should save some calculation results. |

View File

@ -93,7 +93,10 @@ def go_to_detail_page(id: str) -> str:
@app.callback(
Output("select_company", "options"), Input("select_company", "search_value")
)
@cached(cache=TTLCache(maxsize=100, ttl=60), key=lambda search_value: search_value)
@cached(
cache=TTLCache(maxsize=100, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))),
key=lambda search_value: search_value,
)
def update_options(search_value: str) -> list:
"""Update dropdown options based on user input.

View File

@ -69,7 +69,7 @@ def get_finance_data(session: Session) -> pd.DataFrame:
@cached( # type: ignore
cache=TTLCache(maxsize=100, ttl=600),
cache=TTLCache(maxsize=100, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))),
key=lambda session, company_id: hash((company_id, str(session.bind))),
)
def get_finance_data_of_one_company(session: Session, company_id: int) -> pd.DataFrame:

View File

@ -1,4 +1,6 @@
"""Header elements for Dash."""
import os
from cachetools import TTLCache, cached
from dash import dcc, html
@ -52,7 +54,7 @@ def create_header(options: dict[int, str]) -> html:
@cached(
cache=TTLCache(maxsize=100, ttl=600), key=lambda selected_name: hash(selected_name) # type: ignore
cache=TTLCache(maxsize=100, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))), key=lambda selected_name: hash(selected_name) # type: ignore
)
def create_selection_header(selected_name: str) -> html.Div:
"""Create company header based on selected company.

View File

@ -1,4 +1,6 @@
"""Company detail page."""
import os
import dash
from cachetools import TTLCache, cached
from dash import Input, Output, callback, html
@ -16,7 +18,7 @@ dash.register_page(
)
@cached(cache=TTLCache(maxsize=100, ttl=600), key=lambda value: hash(value)) # type: ignore
@cached(cache=TTLCache(maxsize=100, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))), key=lambda value: hash(value)) # type: ignore
def layout(value: str = "1") -> html:
"""Defines the layout of the company page.

View File

@ -1,4 +1,5 @@
"""Content of home page."""
import os
from functools import lru_cache
from typing import Final
@ -87,7 +88,7 @@ def update_table(
return table_df.to_dict("records"), columns # type: ignore
@cached(TTLCache(20, ttl=600))
@cached(TTLCache(50, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))))
def _update_figure( # noqa: PLR0913
selected_metric: str,
switch_edge_annotation_value: bool,

View File

@ -1,4 +1,6 @@
"""Person detail page."""
import os
import dash
from cachetools import TTLCache, cached
from dash import Input, Output, callback, html
@ -12,7 +14,7 @@ dash.register_page(
)
@cached(cache=TTLCache(maxsize=100, ttl=60), key=lambda value: hash(value)) # type: ignore
@cached(cache=TTLCache(maxsize=100, ttl=int(os.getenv("PYTHON_CACHE_TTL", "3600"))), key=lambda value: hash(value)) # type: ignore
def layout(value: str = "1") -> html.Div:
"""Defines the layout of the person detail page.