We'll create fresh WordPress site with Jinx Fast-Cache installed. You have 20 minutes to test the plugin after that site we'll be deleted.
Jinx Fast-Cache provides a very simple but efficient way of full page caching to WordPress.
It will generate static HTML files which will be called using your servers rewrite rules.
This feature will bypass the whole PHP process and render only a simple HTML file without the whole overhead.
After activating the plugin, it will modify your .htaccess file. If this is not possible, make sure to enter the rules by yourself:
# BEGIN Jinx Fast-Cache
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/wp-content/jinx-fast-cache/%{HTTP_HOST}/%{REQUEST_URI}/%{QUERY_STRING}/index.html -s
RewriteCond %{REQUEST_METHOD} GET
RewriteRule .* /wp-content/jinx-fast-cache/%{HTTP_HOST}/%{REQUEST_URI}/%{QUERY_STRING}/index.html [L]
# END Jinx Fast-Cache
When using nginx, make sure to add the following rules:
set $cache_path false;
if ($request_method = GET) {
set $cache_path /wp-content/jinx-fast-cache/$host/$uri/$args/index.html;
}
location / {
try_files $cache_path $uri $uri/ /index.php?$query_string;
}
You may flush, warm or refresh (flush & warm) single or multiple URLs using the buttons in the admin bar.
By default all posts will be automatically warmed after they have been saved and flushed after they have been deleted or put on draft.
The warm process will create a queue, which will be handled in a scheduled task (cron). When warming up a single post, it will skip the queue.
The plugin will automatically flush and warm the cache after an update has been completed.
Jinx Fast-Cache is made for developers. So far no admin panel is available, but you may modify a lot of it’s behaviors using filters.
Jinx Fast-Cache also provides the feature to inject dynamic content into your pages. If you eg. want to print the users name on the page, you may inject it via ajax.
You may also use a placeholder to let your users know, that the content will be loading eg. “loading …”.
Inject a template:
do_action('jinx_fast_cache_inject_template', 'user');
do_action('jinx_fast_cache_inject_template', 'user', 'loading ...');
This has the same effect as:
do_action('jinx_fast_cache_inject', 'get_template_part', ['user']);
do_action('jinx_fast_cache_inject', 'get_template_part', ['user'], 'loading ...');
You may call every public function of PHP, your theme or any plugin:
do_action('jinx_fast_cache_inject', 'date', ['Y']);
do_action('jinx_fast_cache_inject', 'my_function', ['param1', 'param2']);
do_action('jinx_fast_cache_inject', 'namespace\MyClass::myMethod', ['param1', 'param2']);
do_action('jinx_fast_cache_inject', ['namespace\MyClass', 'myMethod'], ['param1', 'param2']);
The first parameter is the function call, the second parameter is an array or arguments passed to this function and the third parameter is the placeholder.
Inside the editor, you may also use shortcodes to inject content.
[jinx_fast_cache_inject]My dynamic content or other shortcodes can be used here[/jinx_fast_cache_inject]
[jinx_fast_cache_inject placeholder="loading..."]My dynamic content or other shortcodes can be used here[/jinx_fast_cache_inject]
Every shortcode or block between “jinx_fast_cache_inject” will be parsed and injected via ajax. Note that this may cause problems when working with JS events.
You may trigger custom JS after dynamic content has been injected.
Using jQuery:
$('.element').on('jinx-fast-cache-inject', function(e) {
// so smth. with e.target or this
});
Using VanillaJS:
element.addEventListener('jinx-fast-cache-inject' (e) => {
// so smth. with e.target
}, false);<h3>Tags</h3>
Even there are some filters to build a relation between URLs, tags are an easier way to do this.
You may connect multiple URLs with tags, so if one URL gets flushed, it will also flush URLs with the same tag.
Tags can be used inside the editor by using the shortcode:
[jinx_fast_cache tags="foo,bar"]
Or you can use it inside your templates by calling the action:
do_action('jinx_fast_cache', ['tags' => 'foo,bar']);
do_action('jinx_fast_cache', ['tags' => ['foo', 'bar']]);
A usecase for tags might be to connect single posts with your page for posts. So if a single post will be flushed, the page for posts and all other posts will also be flushed.
You may also add multiple tags by calling the shortcode or action multiple times. This will work very well when using blocks or other shortcodes.
As you have seen already, you may set a cache duration globally by using the filter ‘jinx_fast_cache_duration’.
However, if there is a specific URL eg. the front page, you may want to change the duration.
You may use a shortcode like this:
[jinx_fast_cache duration="3600"]
[jinx_fast_cache duration="12 hours"]
Or you can use it inside your templates by calling the action:
do_action('jinx_fast_cache', ['duration' => 3600]);<h3>Hits</h3>
Be aware that you can set tags and the cache duration in just one call.
[jinx_fast_cache duration="3600" tags="foo,bar"]
Or you can use it inside your templates by calling the action:
do_action('jinx_fast_cache', ['duration' => 3600, 'tags' => 'foo,bar']);
do_action('jinx_fast_cache', ['duration' => 3600, 'tags' => ['foo', 'bar']]);
Note that tags will accept a string or an array.