dk-pdf icon indicating copy to clipboard operation
dk-pdf copied to clipboard

Add a cache subsystem

Open gjedeer opened this issue 6 years ago • 1 comments

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 avatar Oct 02 '18 12:10 gjedeer

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

gjedeer avatar Oct 02 '18 12:10 gjedeer