# searchpro/1.9.5/inc/thirdparty/server/Nginx.php

BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS &amp; JavaScript, version 1.9.5. 28 lines.

- Page: https://pluginprobe.com/plugins/searchpro/1.9.5/code/inc/thirdparty/server/Nginx.php
- Raw: https://pluginprobe.com/plugins/searchpro/1.9.5/raw/inc/thirdparty/server/Nginx.php
- Modified: 2024-07-08T17:03:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/searchpro/1.9.5/code/inc/thirdparty/server/Nginx.php#L10-L20`.

```php
<?php 
if (!defined('ABSPATH')) exit;

class Nginx extends berqIntegrations {
    function __construct() {
        add_action('berqwp_flush_all_cache', [$this, 'flush_cache']);
        add_action('berqwp_stored_page_cache', [$this, 'flush_cache']);
    }
    
    function flush_cache()
    {
        $is_nginx = stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false;

        if ($is_nginx) {
            // Clear nginx cache

            // Common cache dirs
            $dirs = ['/var/run/nginx-cache', '/var/cache/nginx', '/var/lib/nginx/cache'];

            foreach ($dirs as $dir) {
                berqwp_unlink_recursive($dir);
            }

        }
    }
}

new Nginx();
```
