# solid-performance/1.1.0/src/Performance/Config/Advanced_Cache.php

Solid Performance – Your No-Code Caching, Performance, &amp; Page Speed Solution, version 1.1.0. 81 lines.

- Page: https://pluginprobe.com/plugins/solid-performance/1.1.0/code/src/Performance/Config/Advanced_Cache.php
- Raw: https://pluginprobe.com/plugins/solid-performance/1.1.0/raw/src/Performance/Config/Advanced_Cache.php
- Modified: 2024-08-12T20:38:26+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/solid-performance/1.1.0/code/src/Performance/Config/Advanced_Cache.php#L10-L20`.

```php
<?php
/**
 * All functionality related to creating and modifying the advanced-cache.php drop-in.
 *
 * @since 0.1.0
 *
 * @package SolidWP\Performance
 */

namespace SolidWP\Performance\Config;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class to handle all functionality related to the advanced-cache.php drop-in.
 *
 * @since 0.1.0
 *
 * @package SolidWP\Performance
 */
class Advanced_Cache {

	/**
	 * The current version of the advanced cache file.
	 *
	 * @since 0.1.0
	 *
	 * @var string
	 */
	private string $version = '0.1.0';

	/**
	 * Generates a copy of an advanced-cache.php template and adds it to the wp-content directory.
	 *
	 * @since 0.1.0
	 *
	 * @param string $template    Full path to a template used when generating the drop-in.
	 * @param string $destination Full path where the advanced-cache drop-in should be placed. Defaults to the wp-content directory.
	 *
	 * @return bool
	 */
	public function generate( string $template = '', string $destination = '' ): bool {
		$filesystem = swpsp_direct_filesystem();

		$template = $template ?: dirname( SWPSP_PLUGIN_FILE ) . '/src/views/cache/advanced-cache.php';

		// The plugin directory relative to WP_CONTENT_DIR.
		$plugin_dir = basename( WP_PLUGIN_DIR ) . '/' . basename( dirname( SWPSP_PLUGIN_FILE ) );

		$advanced_cache_content = $filesystem->get_contents( $template );

		$advanced_cache_content = preg_replace( '/{{swpsp-cache-dir}}/', swpsp_config_get( 'page_cache.cache_dir' ), $advanced_cache_content );
		$advanced_cache_content = preg_replace( '/{{swpsp-plugin-file}}/', SWPSP_PLUGIN_FILE, $advanced_cache_content );
		$advanced_cache_content = preg_replace( '/{{swpsp-plugin-dir}}/', $plugin_dir, $advanced_cache_content );
		$advanced_cache_content = preg_replace( '/{{swpsp-advanced-cache-version}}/', $this->version, $advanced_cache_content );

		$destination = $destination ?: WP_CONTENT_DIR . '/advanced-cache.php';

		return $filesystem->put_contents( $destination, $advanced_cache_content, swpsp_get_file_mode() );
	}

	/**
	 * Removes the advanced-cache drop-in.
	 *
	 * @since 0.1.0
	 *
	 * @return bool
	 */
	public function remove(): bool {
		$file = WP_CONTENT_DIR . '/advanced-cache.php';

		if ( ! is_file( $file ) ) {
			return true; // There is no file to remove, just return successfully.
		}

		return swpsp_direct_filesystem()->delete( $file );
	}
}

```
