Caching generated documents - best practice

Hi

Right now I’m caching generated documents on the filesystem and calculate a hash to detect a change in the data used for generation. The generation is done in an action controller. Is there an option to use the internal caching system to store my cached documents there? Otherwise my solution is working.

Best,
Jan

Hi, some more technical background of what you are generating and what kind of documents those are would be helpful to find a good answer :slight_smile:

Currently I primarily generate PDF files, but also some Word templates (dotx) and Excel files. With very few exceptions, the files are up to 500 kilobytes in size. I am currently calculating whether the data is still up to date. If so, I read it from the file system - otherwise I generate the files, store them on the file system, delete the outdated file and deliver it.

For example, I deliver a dotx file as follows:

$this->response->setContentType(‘application/vnd.openxmlformats-officedocument.wordprocessingml.template’);
$this->response->addHttpHeader(‘Content-Disposition’, ‘attachment; filename=“testdatei.dotx”’);
return file_get_contents($localCopy);

How about using Flowpack.FullpageCache for that. That package caches http responses via a middleware.

You would basically add the cache enable and cache lifetime header (names are constants in the full page cache package) to the response.

Offcourse you could also use a custom http middleware to cache the responses.