Dinamiko / dk-pdf

WordPress to PDF made easy
https://wordpress.org/plugins/dk-pdf
26 stars 23 forks source link

Add a cache subsystem #71

Open gjedeer opened 5 years ago

gjedeer commented 5 years ago

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

It's using filesystem for the cache: I've contemplated using wpcache* 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:

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 commented 5 years ago

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