dk-pdf
dk-pdf copied to clipboard
Add a cache subsystem
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:
- It's not persistent out of the box
- 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.
BTW, I see you're reformatting the code back to standard, perhaps I should revert 51957db ?