Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
litespeed_wiki:cache:lscwp:api [2018/09/24 20:17] Lisa Clarke [Hooks] Added hook_vary_add |
litespeed_wiki:cache:lscwp:api [2019/03/27 19:55] Lisa Clarke [Nonce Issues] |
||
---|---|---|---|
Line 4: | Line 4: | ||
However, if the plugin needs to update some data, and the cache does not automatically purge the cached page, you may be required to write an integration script to remedy this or invoke LSCWP's API. | However, if the plugin needs to update some data, and the cache does not automatically purge the cached page, you may be required to write an integration script to remedy this or invoke LSCWP's API. | ||
===== Nonce Issues ===== | ===== Nonce Issues ===== | ||
+ | The WordPress ''nonce'' makes caching difficult with most plugins, however the LiteSpeed API (described [[litespeed_wiki:cache:lscwp:api#api |below]] in more detail) has an elegant solution. | ||
- | The WordPress ''nonce'' makes caching difficult with most plugins, however the LiteSpeed API (described [[litespeed_wiki:cache:lscwp:api#api |below]] in more detail) includes a work-around. | + | If your plugin uses a default nonce, then //LiteSpeed Cache will automatically treat that nonce as an ESI block//. This ensures the nonce is cached for only 12 hours, separate from the TTL of the page that it is on. You don't have to do anything special for this to work. |
- | Anywhere in your code that you would have used | + | If your plugin uses a custom nonce, however, you will need to register the nonce action with our API before you use it. |
- | + | ||
- | wp_create_nonce( 'example' ) | + | |
- | you should instead use | + | For example, if you have the following line in your code |
+ | |||
+ | wp_create_nonce( 'example' ); | ||
+ | |||
+ | Then you need to call the API somewhere before that line, like so: | ||
- | method_exists( 'LiteSpeed_Cache_API', 'nonce' ) ? LiteSpeed_Cache_API::nonce( 'example' ) : wp_create_nonce( 'example' ) | + | LiteSpeed_Cache_API::nonce_action( 'example' ) |
- | NOTE: Replace ''example'' with your own string. | + | NOTE: Replace ''example'' with your own parameter. |
- | This new code checks to see that LiteSpeed is available, and if it is, the LiteSpeed API function is used in place of the built-in WP function. | + | Once registered with our API, your custom nonce will be treated as an ESI block as long as your users have ESI enabled. (If ESI is not enabled, the API will call the native WordPress nonce function.) |
- | LiteSpeed's function simply creates an ESI block and then runs the WP function inside of that block. ESI ensures the nonce is cached for only 12 hours, separate from the TTL of the page that it is on. | ||
===== Potential for Customization ===== | ===== Potential for Customization ===== | ||
LSCache for WordPress provides functions and hooks that allow you to customize many aspects of cache management, well beyond the nonce issue mentioned above. | LSCache for WordPress provides functions and hooks that allow you to customize many aspects of cache management, well beyond the nonce issue mentioned above. |