问题解析:

已知WP Rocket插件带有浏览器缓存,其他缓存插件未测,会导致登录后仍然显示未登录(因为浏览器缓存的原因,除非访客手动清理浏览器缓存,否则之前访问过的页面均会优先调用缓存),此问题可以通过修改插件解决。由于版权问题,此处不提供修改后插件下载,仅提供方法!

解决方法

修改文件:

/wp-content/plugins/wp-rocket/inc/classes/Buffer/class-cache.php

修改后函数:

private function serve_cache_file( $cache_filepath ) {
		header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
		header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );

		/*$if_modified_since = $this->get_if_modified_since();

		// Checking if the client is validating his cache and if it is current.
		if ( $if_modified_since && ( strtotime( $if_modified_since ) === @filemtime( $cache_filepath ) ) ) {
			// Client's cache is current, so we just respond '304 Not Modified'.
			header( $this->config->get_server_input( 'SERVER_PROTOCOL', '' ) . ' 304 Not Modified', true, 304 );
			header( 'Expires: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
			header( 'Cache-Control: no-cache, must-revalidate' );

			$this->log(
				'Serving `304` cache file.',
				[
					'path'     => $cache_filepath,
					'modified' => $if_modified_since,
				],
				'info'
			);
			exit;
		}*/

		// Serve the cache if file isn't store in the client browser cache.
		readfile( $cache_filepath );

		$this->log(
			'Serving cache file.',
			[
				'path'     => $cache_filepath,
				'modified' => $if_modified_since,
			],
			'info'
		);
		exit;
	}

	/**
	 * Serve a gzipped cache file.
	 *
	 * @since  3.3
	 *
	 * @param string $cache_filepath Path to the gzip cache file.
	 */
	private function serve_gzip_cache_file( $cache_filepath ) {
		header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
		header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );

		/*$if_modified_since = $this->get_if_modified_since();

		// Checking if the client is validating his cache and if it is current.
		if ( $if_modified_since && ( strtotime( $if_modified_since ) === @filemtime( $cache_filepath ) ) ) {
			// Client's cache is current, so we just respond '304 Not Modified'.
			header( $this->config->get_server_input( 'SERVER_PROTOCOL', '' ) . ' 304 Not Modified', true, 304 );
			header( 'Expires: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
			header( 'Cache-Control: no-cache, must-revalidate' );

			$this->log(
				'Serving `304` gzip cache file.',
				[
					'path'     => $cache_filepath,
					'modified' => $if_modified_since,
				],
				'info'
			);
			exit;
		}*/

		// Serve the cache if file isn't store in the client browser cache.
		readgzfile( $cache_filepath );

		$this->log(
			'Serving gzip cache file.',
			[
				'path'     => $cache_filepath,
				'modified' => $if_modified_since,
			],
			'info'
		);
		exit;
	}

 

参与评论