I have a little issue regarding my custom block module. The module itself fetches weather data via json-request and the data is shown as a 4-day weather forecast to the user. As the weather should be actualized every day I want to set a "maximum cache time" or even disable caching for the whole block. Right now I would have to flush the cash manually every day.
After a little bit of research to that topic I found out that using
'max-age' in the build() function would do the trick but it does not affect the caching for anonymous users at all.
\Drupal::service('page_cache_kill_switch')->trigger(); would disable the cache for a specific page or content-type but I don't want to disable the caching for a whole page at once.
So how can I trigger the caching for my custom-block? Or is there even a way to disable the caching for a certain part of the code e.g. the json-request in my case?