On my site I do this:
I got a form with this field:
'myfile' => [
'#title' => $this->t('MyTitle'),
'#type' => 'managed_file',
'#upload_location' => 'public://myfolder',
],
And MyController:
$myform = \Drupal::formBuilder()->getForm('Drupal\[mymodule]\Form\[myclassform]');
This variable I pass to Twig template.
On my template:
{{ myform }}
Every is ok.
But when the page is cached I got this error when i upload a file:
An unrecoverable error occurred. Use of this form has expired. Try reloading the page and submitting again.
I dont use memcache or CacheRoute, only drupal cache for anonymous user.
How I fix that? Is possible not cached the form?