예제 #1
0
 /**
  * flush_post_url()
  *
  * @param $link
  * @internal param string $url
  * @internal param int $timeout
  * @return void
  */
 static function flush_post_url($link)
 {
     $cache_id = md5($link);
     wp_cache_delete($cache_id, 'url2post_id');
     if (static_cache) {
         static $permalink_structure;
         if (!isset($permalink_structure)) {
             $permalink_structure = get_option('permalink_structure');
         }
         # 5 min throttling in case the site is getting hammered by comments
         $timeout = !is_admin() && current_filter() == 'wp_update_comment_count' ? 300 : false;
         if ($permalink_structure) {
             $path = trim(preg_replace("|^[^/]+://[^/]+|", '', $link), '/');
             cache_fs::flush('/static/' . $path, $timeout, false);
         }
     }
     if (memory_cache) {
         wp_cache_delete($cache_id, 'cached_headers');
         wp_cache_delete($cache_id, 'cached_buffers');
     } elseif (static_cache) {
         cache_fs::flush('/semi-static/' . $cache_id . '.meta', $timeout, false);
         cache_fs::flush('/semi-static/' . $cache_id . '.html', $timeout, false);
     }
 }
예제 #2
0
 /**
  * save_options()
  *
  * @return void
  **/
 static function save_options()
 {
     if (!$_POST || !current_user_can('manage_options')) {
         return;
     }
     if (function_exists('is_super_admin') && !is_super_admin()) {
         return;
     }
     check_admin_referer('sem_cache');
     $timeout = false;
     switch ($_POST['action']) {
         case 'clean':
             $timeout = cache_timeout;
         case 'flush':
             if (function_exists('is_multisite') && is_multisite()) {
                 echo '<div class="error">' . "\n" . '<p>' . '<strong>' . __('On multisite installations, the cache can only be bulk-flushed manually.', 'sem-cache') . '</strong>' . '</p>' . '</div>' . "\n";
                 break;
             }
             if (!$timeout) {
                 cache_fs::flush('/assets/');
             }
             cache_fs::flush('/static/', $timeout);
             cache_fs::flush('/semi-static/', $timeout);
             wp_cache_flush();
             remove_action('flush_cache', array('sem_cache', 'flush_cache'));
             do_action('flush_cache');
             echo '<div class="updated fade">' . "\n" . '<p>' . '<strong>' . __('Cache Flushed.', 'sem-cache') . '</strong>' . '</p>' . "\n" . '</div>' . "\n";
             break;
         case 'off':
             self::disable_static();
             self::disable_memcached();
             self::disable_assets();
             self::disable_gzip();
             echo '<div class="updated fade">' . "\n" . '<p>' . '<strong>' . __('Settings saved. Cache Disabled.', 'sem-cache') . '</strong>' . '</p>' . "\n" . '</div>' . "\n";
             break;
         default:
             $can_static = self::can_static();
             $can_memcached = self::can_memcached();
             $can_query = self::can_query();
             $can_assets = self::can_assets();
             $can_gzip = self::can_gzip();
             if ($_POST['action'] != 'on') {
                 $static_cache = $can_static && isset($_POST['static_cache']);
                 $memory_cache = $can_memcached && isset($_POST['memory_cache']);
                 $query_cache = $can_query && isset($_POST['query_cache']);
                 $object_cache = $can_memcached && (isset($_POST['object_cache']) || isset($_POST['query_cache']) || isset($_POST['memory_cache']));
                 $asset_cache = $can_assets && isset($_POST['asset_cache']);
                 $gzip_cache = $can_gzip && isset($_POST['gzip_cache']);
             } else {
                 $static_cache = $can_static;
                 $memory_cache = $can_memcached;
                 $query_cache = $can_query;
                 $object_cache = $can_memcached;
                 $asset_cache = $can_assets;
                 $gzip_cache = $can_gzip;
             }
             //			$static_static &= !( function_exists('is_multisite') && is_multisite() );
             update_site_option('static_cache', (int) $static_cache);
             update_site_option('memory_cache', (int) $memory_cache);
             update_site_option('query_cache', (int) $query_cache);
             update_site_option('object_cache', (int) $object_cache);
             update_site_option('asset_cache', (int) $asset_cache);
             update_site_option('gzip_cache', (int) $gzip_cache);
             #dump($static_cache, $memory_cache, $query_cache, $object_cache, $asset_cache, $gzip_cache);
             self::enable_static();
             self::enable_memcached();
             self::enable_assets();
             self::enable_gzip();
             echo '<div class="updated fade">' . "\n" . '<p>' . '<strong>' . __('Settings saved. Cache Enabled.', 'sem-cache') . '</strong>' . '</p>' . "\n" . '</div>' . "\n";
             if (!get_site_option('object_cache') && class_exists('object_cache')) {
                 # do a hard object flush
                 wp_cache_flush();
             }
             break;
     }
     if (file_exists(WP_CONTENT_DIR . '/cache/wp_cache_mutex.lock')) {
         cache_fs::flush('/');
     }
 }