Plugin Directory

Changeset 3157468


Ignore:
Timestamp:
09/25/2024 10:56:04 AM (19 months ago)
Author:
ergonet
Message:

add nginx cache purge method

Location:
ergonet-varnish-cache
Files:
1 added
1 edited
3 copied

Legend:

Unmodified
Added
Removed
  • ergonet-varnish-cache/tags/1.0.9/varnishCache.php

    r3152539 r3157468  
    123123    }
    124124
     125    function populateFrontPageCache()
     126    {
     127        $url = get_home_url();
     128        $command = $this->populateCache($url);
     129    }
     130
    125131    function purgeAll()
    126132    {
    127133        $url = get_home_url()."/.*";
     134        $command = $this->execCachePurge($url);
     135        $url = get_home_url()."/*";
    128136        $command = $this->execCachePurge($url);
    129137    }
     
    137145        $url = get_permalink( $post_id );
    138146        $command = $this->execCachePurge($url);
     147    }
     148
     149    function populatePostCache($post_id)
     150    {
     151        if ( wp_is_post_revision( $post_id ) ) {
     152            return;
     153        }
     154
     155        $url = get_permalink( $post_id );
     156        $command = $this->populateCache($url);
     157    }
     158
     159    function populatePostCategoriesCache($post_id)
     160    {
     161        $categorie = wp_get_post_categories($post_id);
     162        foreach ($categorie as $category_id) {
     163            $url = get_category_link($category_id);
     164            $command = $this->populateCache($url);
     165        }
    139166    }
    140167
     
    146173            $command = $this->execCachePurge($url);
    147174        }
     175    }
     176
     177    function populateCache( $url )
     178    {
     179        $url = $this->getUrl($url);
     180        $params = array(
     181            'method' => 'GET',
     182            'user-agent' => 'wp_purgeCache',
     183            'sslverify' => false,
     184            'headers' => array(
     185                'host' => $url['hostname']
     186            ),
     187            'redirection' => 0,
     188        );
     189        $response = wp_remote_request($url['url'], $params);
    148190    }
    149191
  • ergonet-varnish-cache/trunk/varnishCache.php

    r3152539 r3157468  
    123123    }
    124124
     125    function populateFrontPageCache()
     126    {
     127        $url = get_home_url();
     128        $command = $this->populateCache($url);
     129    }
     130
    125131    function purgeAll()
    126132    {
    127133        $url = get_home_url()."/.*";
     134        $command = $this->execCachePurge($url);
     135        $url = get_home_url()."/*";
    128136        $command = $this->execCachePurge($url);
    129137    }
     
    137145        $url = get_permalink( $post_id );
    138146        $command = $this->execCachePurge($url);
     147    }
     148
     149    function populatePostCache($post_id)
     150    {
     151        if ( wp_is_post_revision( $post_id ) ) {
     152            return;
     153        }
     154
     155        $url = get_permalink( $post_id );
     156        $command = $this->populateCache($url);
     157    }
     158
     159    function populatePostCategoriesCache($post_id)
     160    {
     161        $categorie = wp_get_post_categories($post_id);
     162        foreach ($categorie as $category_id) {
     163            $url = get_category_link($category_id);
     164            $command = $this->populateCache($url);
     165        }
    139166    }
    140167
     
    146173            $command = $this->execCachePurge($url);
    147174        }
     175    }
     176
     177    function populateCache( $url )
     178    {
     179        $url = $this->getUrl($url);
     180        $params = array(
     181            'method' => 'GET',
     182            'user-agent' => 'wp_purgeCache',
     183            'sslverify' => false,
     184            'headers' => array(
     185                'host' => $url['hostname']
     186            ),
     187            'redirection' => 0,
     188        );
     189        $response = wp_remote_request($url['url'], $params);
    148190    }
    149191
Note: See TracChangeset for help on using the changeset viewer.