<?php

/**
 * Plugin name: Spider-Cache
 * Plugin URI:  https://wordpress.org/plugins/wp-spider-cache/
 * Description: Fully rendered pages stored in & served from Memcached.
 * Version:     2.1.0
 */
// Exit if accessed directly
defined('ABSPATH') || exit;
// Required files
require_once WP_CONTENT_DIR . '/plugins/wp-spider-cache/includes/functions.php';
// Initialize the caches
if (!wp_skip_output_cache()) {
    wp_object_cache_init();
    wp_output_cache_init();
}
 /**
  * Clear a cached URL
  *
  * @since 2.3.0
  *
  * @param string $url
  *
  * @return boolean
  */
 public static function clean_url($url = '')
 {
     // Bail if no URL
     if (empty($url)) {
         return false;
     }
     // Bail if no persistent output cache
     if (!function_exists('wp_output_cache')) {
         return false;
     }
     // Normalize the URL
     if (0 === strpos($url, 'https://')) {
         $url = str_replace('https://', 'http://', $url);
     }
     if (0 !== strpos($url, 'http://')) {
         $url = 'http://' . $url;
     }
     $url_key = md5($url);
     // Get cache objects
     $output_cache = wp_output_cache_init();
     $object_cache = wp_object_cache_init();
     // Bail if either cache is missing
     if (empty($output_cache) || empty($object_cache)) {
         return;
     }
     wp_cache_add("{$url_key}_version", 0, $output_cache->group);
     $retval = wp_cache_incr("{$url_key}_version", 1, $output_cache->group);
     $output_cache_no_remote_group_key = array_search($output_cache->group, (array) $object_cache->no_remote_groups);
     // The *_version key needs to be replicated remotely, otherwise invalidation won't work.
     // The race condition here should be acceptable.
     if (false !== $output_cache_no_remote_group_key) {
         unset($object_cache->no_remote_groups[$output_cache_no_remote_group_key]);
         $retval = wp_cache_set("{$url_key}_version", $retval, $output_cache->group);
         $object_cache->no_remote_groups[$output_cache_no_remote_group_key] = $output_cache->group;
     }
     return $retval;
 }
/**
 * Returns the Output Cache Global.
 *
 * @since 2.1.0
 *
 * @global  WP_Spider_Cache_Output  $wp_output_cache   WordPress Output Cache
 * @return  object
 */
function wp_output_cache()
{
    if (!isset($GLOBALS['wp_output_cache'])) {
        wp_output_cache_init();
    }
    return $GLOBALS['wp_output_cache'];
}