Skip to content

Commit

Permalink
Adjust cache ttl values
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Sep 22, 2020
1 parent 624b56e commit b5e7680
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
30 changes: 24 additions & 6 deletions wetterdienst/additionals/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,42 @@
# Define cache regions.
metaindex_cache = make_region().configure(
backend,
expiration_time=1 * 60,
arguments={"filename": os.path.join(cache_dir, "metaindex_1min.dbm")},
expiration_time=60 * 60 * 12,
arguments={"filename": os.path.join(cache_dir, "metaindex.dbm")},
)

fileindex_cache_five_minutes = make_region().configure(
backend,
expiration_time=5 * 60,
arguments={"filename": os.path.join(cache_dir, "fileindex_5min.dbm")},
expiration_time=60 * 5,
arguments={"filename": os.path.join(cache_dir, "fileindex_5m.dbm")},
)

fileindex_cache_one_hour = make_region().configure(
backend,
expiration_time=60 * 60,
arguments={"filename": os.path.join(cache_dir, "fileindex_60min.dbm")},
arguments={"filename": os.path.join(cache_dir, "fileindex_1h.dbm")},
)

fileindex_cache_twelve_hours = make_region().configure(
backend,
expiration_time=60 * 60 * 12,
arguments={"filename": os.path.join(cache_dir, "fileindex_12h.dbm")},
)

payload_cache_five_minutes = make_region().configure(
backend,
expiration_time=60 * 5,
arguments={"filename": os.path.join(cache_dir, "payload_5m.dbm")},
)

payload_cache_one_hour = make_region().configure(
backend,
expiration_time=60 * 60,
arguments={"filename": os.path.join(cache_dir, "payload_60min.dbm")},
arguments={"filename": os.path.join(cache_dir, "payload_1h.dbm")},
)

payload_cache_twelve_hours = make_region().configure(
backend,
expiration_time=60 * 60 * 12,
arguments={"filename": os.path.join(cache_dir, "payload_12h.dbm")},
)
7 changes: 4 additions & 3 deletions wetterdienst/download/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

from requests.exceptions import InvalidURL

from wetterdienst.additionals.cache import payload_cache_one_hour
from wetterdienst.additionals.cache import payload_cache_five_minutes, \
payload_cache_twelve_hours
from wetterdienst.constants.access_credentials import DWDCDCBase
from wetterdienst.download.download_services import download_file_from_dwd
from wetterdienst.enumerations.datetime_format_enumeration import DatetimeFormat
Expand Down Expand Up @@ -55,7 +56,7 @@ def _download_climate_observations_data(remote_file: Union[str, Path]) -> BytesI
return BytesIO(__download_climate_observations_data(remote_file=remote_file))


@payload_cache_one_hour.cache_on_arguments()
@payload_cache_five_minutes.cache_on_arguments()
def __download_climate_observations_data(remote_file: Union[str, Path]) -> bytes:
try:
zip_file = download_file_from_dwd(remote_file, DWDCDCBase.CLIMATE_OBSERVATIONS)
Expand Down Expand Up @@ -114,7 +115,7 @@ def download_radolan_data(
return _extract_radolan_data(date_time, archive_in_bytes)


@payload_cache_one_hour.cache_on_arguments()
@payload_cache_twelve_hours.cache_on_arguments()
def _download_radolan_data(remote_radolan_filepath: str) -> BytesIO:
"""
Function (cached) that downloads the RADOLAN file
Expand Down
6 changes: 3 additions & 3 deletions wetterdienst/indexing/file_index_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from wetterdienst.additionals.cache import (
fileindex_cache_five_minutes,
fileindex_cache_one_hour,
fileindex_cache_one_hour, fileindex_cache_twelve_hours,
)
from wetterdienst.constants.access_credentials import (
DWD_CDC_PATH,
Expand All @@ -29,7 +29,7 @@
)


@fileindex_cache_five_minutes.cache_on_arguments()
@fileindex_cache_twelve_hours.cache_on_arguments()
def create_file_index_for_climate_observations(
parameter: Parameter, time_resolution: TimeResolution, period_type: PeriodType
) -> pd.DataFrame:
Expand Down Expand Up @@ -66,7 +66,7 @@ def create_file_index_for_climate_observations(
]


@fileindex_cache_one_hour.cache_on_arguments()
@fileindex_cache_five_minutes.cache_on_arguments()
def create_file_index_for_radolan(time_resolution: TimeResolution) -> pd.DataFrame:
"""
Function used to create a file index for the RADOLAN product. The file index will
Expand Down

0 comments on commit b5e7680

Please sign in to comment.