Prevent block from caching I have a custom block that reads information from the database. As the user will be filling out a form, refreshing the page and viewing the block it cannot be cached. How do I fix this?

I have tried:

$build['#cache']['max-age'] = 0;


And this did not fix it.

I also tried copying the code from the custom block to the top of the form, so it runs as part of the page, here it doesn't cache. Unfortunately this isn't a solution as I need the block on another page also.
Drupal caches the already rendered block and doesn't check for changes in code, so after changing #cache in the block's render array as shown, you'd still need to use drush or the UI option to force-clear the render cache after changing this.

As an alternative, try deleting the block instance and placing it again.

Since you don't indicate that the form is making changes to the database, it's not clear if there is any cache tag to associate - is it data input or something more like a search form?