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

Add a cache subsystem #71

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Add a cache subsystem #71

wants to merge 13 commits into from

Conversation

gjedeer
Copy link

@gjedeer gjedeer commented Oct 2, 2018

Since PDF generation can take some time, I've implemented file cache.

It's using filesystem for the cache: I've contemplated using wp_cache_* family of functions but:

  1. It's not persistent out of the box
  2. Storing PDFs in Redis or Memcached is an overkill

File names are salted hashes of post ID. Used salt is LOGGED_IN_SALT, which should be unique per-site and thus, result in unguessable file names (important for non-public posts).

It has two events invalidating the cache:

  • Saving the post/page invalidates a single PDF
  • Saving dk-pdf settings invalidates all cached PDFs

There is a new setting for enabling/disabling the cache since it may not always be appropriate.

Since the settings are stored using get_option() and it adds a noticeable delay, there's also an alternative way to enable the DKPDF cache:

define('DKPDF_CACHE', 'on');

It's faster by 300ms on one server and 1s on another.

@gjedeer
Copy link
Author

gjedeer commented Oct 2, 2018

BTW, I see you're reformatting the code back to standard, perhaps I should revert
51957db ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants