{"id":2045,"date":"2025-03-18T16:21:48","date_gmt":"2025-03-18T07:21:48","guid":{"rendered":"https:\/\/cooss.net\/delete-cache-using-accelerator-api\/"},"modified":"2025-03-18T16:36:00","modified_gmt":"2025-03-18T07:36:00","slug":"delete-cache-using-accelerator-api","status":"publish","type":"post","link":"https:\/\/cooss.net\/en\/delete-cache-using-accelerator-api\/","title":{"rendered":"Delete cache using Accelerator API."},"content":{"rendered":"\n<p>Seraphinite Accelerator is a powerful tool that optimizes the speed of WordPress websites and manages caching. In this article, we will cover how to delete the generated cache using the API.<\/p>\n\n\n\n<p>At COOSS.NET, when writing articles in Korean, we have created a function in the theme&#8217;s functions.php that automatically performs translations, and on translated pages, links to select other languages are generated. However, there was an issue where, after the initial article is cached by the Accelerator, even if there are translated pages, the link to the translated page does not appear on the cached page.<\/p>\n\n\n\n<p>Of course, it is possible to set the Accelerator to periodically refresh the cache, but it is cumbersome to change the settings every time just to refresh the translated pages. Moreover, forcing a complete site cache refresh is not efficient, so we looked for an API that would force the original page cache to be regenerated once the translation is complete.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Seraphinite Accelerator API Overview<\/strong><\/h2>\n\n\n\n<p>Seraphinite Accelerator provides the following API functionalities.<\/p>\n\n\n\n<p><strong>OperateCache &#8211; Cache Management<\/strong><br>You can delete or regenerate the cache of a specific page.<\/p>\n\n\n\n<p><strong>GetCacheStatus &#8211; Check Cache Status<\/strong><br>You can check whether a specific URL is cached.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Cache Management API (OperateCache)<\/strong><\/h2>\n\n\n\n<p>The OperateCache function can delete or regenerate the cache of a specific URL as needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Usage<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>seraph_accelAPI::OperateCache( $op, $obj );<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Parameter Description<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>$op (Cache management option)\n<ul class=\"wp-block-list\">\n<li>CACHE_OP_REVALIDATE \u2192 Cache revalidation<\/li>\n\n\n\n<li>CACHE_OP_CHECK_REVALIDATE \u2192 Revalidate cache if necessary<\/li>\n\n\n\n<li>CACHE_OP_CLEAR \u2192 Clean up old cache<\/li>\n\n\n\n<li>CACHE_OP_DEL \u2192 Delete cache<\/li>\n\n\n\n<li>CACHE_OP_SRVDEL \u2192 Delete server cache (if possible)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>$obj (URL or relative path to delete)\n<ul class=\"wp-block-list\">\n<li>Enter the URL to delete the cache of a specific page<\/li>\n\n\n\n<li><strong>Enter null to delete the entire site cache<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example of Cache Deletion<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><br>Delete Cache of Specific Page<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>seraph_accelAPI::OperateCache( seraph_accelAPI::CACHE_OP_DEL, '\/mypage\/' );<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Delete Entire Site Cache<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>seraph_accelAPI::OperateCache( seraph_accelAPI::CACHE_OP_DEL, null );<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Delete Cache of Multiple URLs<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$urls = &#091;'\/category\/wordpress\/', '\/tag\/performance\/', '\/custom-post-type\/my-post\/'];\nforeach ($urls as $url) {\n    seraph_accelAPI::OperateCache( seraph_accelAPI::CACHE_OP_DEL, $url );\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Cache Status Check API (GetCacheStatus)<\/h3>\n\n\n\n<p>You can check whether a specific URL is cached and whether cache optimization has been applied.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><br>Usage<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$cache_status = seraph_accelAPI::GetCacheStatus($obj, $headers = &#091;]);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><br>Parameter Description<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>$obj \u2192 URL to check<\/li>\n\n\n\n<li>$headers (optional) \u2192 Pass specific HTTP headers to check the cache\n<ul class=\"wp-block-list\">\n<li>Example: &#8216;User-Agent&#8217; =&gt; &#8216;AppleWebKit\/9999999.99 Mobile&#8217;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Return Values<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Property<\/th><th>Value<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>cache<\/code><\/td><td><code>true<\/code><\/td><td>The page is cached<\/td><\/tr><tr><td><code>cache<\/code><\/td><td><code>false<\/code><\/td><td>The page is not cached<\/td><\/tr><tr><td><code>optimization<\/code><\/td><td><code>true<\/code><\/td><td>Cache optimization completed<\/td><\/tr><tr><td><code>optimization<\/code><\/td><td><code>false<\/code><\/td><td>Cache not optimized<\/td><\/tr><tr><td><code>optimization<\/code><\/td><td><code>null<\/code><\/td><td>No cache<\/td><\/tr><tr><td><code>status<\/code><\/td><td><code>'done'<\/code><\/td><td>Caching completed<\/td><\/tr><tr><td><code>status<\/code><\/td><td><code>'revalidating'<\/code><\/td><td>Cache regeneration in progress<\/td><\/tr><tr><td><code>status<\/code><\/td><td><code>'pending'<\/code><\/td><td>Cache pending<\/td><\/tr><tr><td><code>status<\/code><\/td><td><code>'none'<\/code><\/td><td>Not processed<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Example of Cache Status Check<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$cache_status = seraph_accelAPI::GetCacheStatus('https:\/\/example.com\/mypage\/');\nif ($cache_status&#091;'cache']) {\n    echo 'The page has been cached.';\n} else {\n    echo 'The page has not been cached.';\n}<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a Function to Delete Cache for a List of Specific URLs<\/h2>\n\n\n\n<p>You can create a function to delete the cache of multiple URLs at once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cache Deletion Function<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>function sa_clear_cache_for_urls($urls = &#091;]) {\n    if (!class_exists('seraph_accelAPI')) {\n        error_log('Seraphinite Accelerator API is not loaded.');\n        return false;\n    }\n\n    if (!is_array($urls) || empty($urls)) {\n        error_log('A valid list of URLs was not provided.');\n        return false;\n    }\n\n    foreach ($urls as $url) {\n        if (!empty($url)) {\n            seraph_accelAPI::OperateCache(seraph_accelAPI::CACHE_OP_DEL, $url);\n            error_log('Cache deleted: ' . $url);\n        }\n    }\n\n    return true;\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Usage Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$urls_to_clear = &#091;\n    '\/category\/wordpress\/',\n    '\/tag\/performance\/',\n    '\/custom-post-type\/my-post\/',\n    '\/',\n];\n\nsa_clear_cache_for_urls($urls_to_clear);<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>By defining the function as above, you can pass the original article page address to the function at the point when the translation is complete to refresh the cached content (after deletion, the page will be refreshed at the time it is displayed or as set in the Accelerator settings).<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Seraphinite Accelerator is a powerful tool that optimizes the speed of WordPress websites and manages caching. In this article, we will cover how to delete the generated cache using the API. At COOSS.NET, when writing articles in Korean, we have created a function in the theme&#8217;s functions.php that automatically performs translations, and on translated pages, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107],"tags":[],"class_list":["post-2045","post","type-post","status-publish","format-standard","hentry","category-accelerator-en"],"_links":{"self":[{"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/posts\/2045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/comments?post=2045"}],"version-history":[{"count":0,"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/posts\/2045\/revisions"}],"wp:attachment":[{"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/media?parent=2045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/categories?post=2045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cooss.net\/en\/wp-json\/wp\/v2\/tags?post=2045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}