Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching - add clear cache tool + dev mode bypass #1539

Open
jakejackson1 opened this issue Jun 13, 2024 · 1 comment · Fixed by #1556
Open

Caching - add clear cache tool + dev mode bypass #1539

jakejackson1 opened this issue Jun 13, 2024 · 1 comment · Fixed by #1556

Comments

@jakejackson1
Copy link
Member

jakejackson1 commented Jun 13, 2024

Problem

Currently, PDFs are saved to disk during form submission if the gfpdf_post_save_pdf hook is used, if the PDF is included as an email attachment, when using the Previewer add-on, or using the API.

Those PDFs are then cleaned up from disk:

  • At the end of the form submission process
  • At the end of the background processing queue
  • After the Resend Notification process
  • Every 12 hours (down from 24 hours)

If multiple notifications are sent on form submission with the same PDF attached, the PDF on disk will be used.

When the new Gravity Forms Async Notification feature is used, the PDFs are not currently cleaned up from disk, but this could be done via the gform_post_process_async_notifications hook.

Over the years various problems have cropped up due to the short lifespan of the temporary PDFs, or PDFs not being cleaned up at a suitable time. Some examples include:

As you can see the lifecycle of the PDF being saved to disk is currently unpredictable, and dynamically generating PDFs on demand over a short period of time is not performant.

Solution

Standardize the PDF lifecycle so it's more predicable and performant:

  1. If a PDF is generated (viewed/downloaded/emailed), it will be saved to the temporary directory
  2. If a PDF already exists in the temporary directory, the cached copy will be served
  3. Remove all existing cleanup routines and replace it with a scheduled task that deletes PDFs older than 1 hour
  4. If a form or entry is updated/deleted, the associated PDFs will be cleanup from the temporary directory The 1 hour cleanup routine will handle this automatically.

The short-lived disk cache strikes a balance between security, performance, and easy-of-use for first- and third-party plugins. If emails are delayed, the PDF attachment files will still be available for at least 1 hour to allow for (re)sending. If the same PDF is viewed many times in a short period of time, the cached version will be served. Provided stale copies of the PDF are automatically deleted from disk when form/entry changes are made, users should always receive up-to-date documents.

Gravity PDF is making use of caching more and more throughout the codebase (templates, fonts, PDFs). Should the caches become stale, we need a simple solution for users to flush all caches. Currently this is tied to Debug Mode, but it's a toggle on/off feature – and not a one-off action – which confuses some users.

To make this simpler for users:

  1. Add a new Clear Cache tool that will handle all templates/fonts/pdfs cache clearing
  2. Remove the UI for Debug Mode and auto-enable it when WP_DEBUG is enabled and/or a new filter is used
@jakejackson1 jakejackson1 mentioned this issue Jun 13, 2024
4 tasks
@jakejackson1 jakejackson1 added this to the 6.12 milestone Jul 15, 2024
@jakejackson1 jakejackson1 linked a pull request Jul 23, 2024 that will close this issue
46 tasks
@jakejackson1 jakejackson1 reopened this Jul 31, 2024
@jakejackson1
Copy link
Member Author

Left open as a reminder to document this change

@jakejackson1 jakejackson1 changed the title Caching Caching - add clear cache tool + dev mode bypass Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant