core/core.services.yml | 39 ---------
core/modules/page_cache/page_cache.info.yml | 2 +-
core/modules/page_cache/page_cache.module | 3 +-
core/modules/smart_cache/smart_cache.info.yml | 6 ++
core/modules/smart_cache/smart_cache.module | 31 ++++++++
core/modules/smart_cache/smart_cache.services.yml | 44 +++++++++++
.../src}/EventSubscriber/SmartCacheSubscriber.php | 4 +-
.../RequestPolicy}/DefaultRequestPolicy.php | 6 +-
.../RequestPolicy/DenyNonHtmlRequests.php | 6 +-
.../PageCache/ResponsePolicy/DenyAdminRoutes.php} | 6 +-
.../RequestPolicy/DefaultRequestPolicy.php | 92 ++++++++++++++++++++++
.../src/Tests}/SmartCacheIntegrationTest.php | 10 +--
.../smart_cache_test/smart_cache_test.info.yml | 0
.../smart_cache_test/smart_cache_test.routing.yml | 0
.../src/SmartCacheTestController.php | 0
core/profiles/minimal/minimal.info.yml | 1 +
core/profiles/standard/standard.info.yml | 1 +
core/profiles/testing/testing.info.yml | 5 +-
sites/example.settings.local.php | 5 ++
19 files changed, 201 insertions(+), 60 deletions(-)
diff --git a/core/core.services.yml b/core/core.services.yml
index 0d16985..2fef4a9 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -225,17 +225,6 @@ services:
tags:
- { name: page_cache_response_policy }
- { name: smart_cache_response_policy }
- smart_cache_no_admin_routes:
- class: Drupal\Core\PageCache\ResponsePolicy\NoAdminRoutes
- arguments: ['@current_route_match']
- public: false
- tags:
- - { name: smart_cache_response_policy }
- smart_cache_non_html_requests:
- class: Drupal\Core\PageCache\RequestPolicy\DenyNonHtmlRequests
- public: false
- tags:
- - { name: smart_cache_request_policy }
config.manager:
class: Drupal\Core\Config\ConfigManager
arguments: ['@entity.manager', '@config.factory', '@config.typed', '@string_translation', '@config.storage', '@event_dispatcher']
@@ -937,34 +926,6 @@ services:
tags:
- { name: render.main_content_renderer, format: drupal_modal }
- cache.smart_cache_contexts:
- class: Drupal\Core\Cache\CacheBackendInterface
- tags:
- - { name: cache.bin }
- factory: cache_factory:get
- arguments: [smart_cache_contexts]
- cache.smart_cache_html:
- class: Drupal\Core\Cache\CacheBackendInterface
- tags:
- - { name: cache.bin }
- factory: cache_factory:get
- arguments: [smart_cache_html]
- smart_cache_request_policy:
- class: Drupal\Core\SmartCache\DefaultRequestPolicy
- tags:
- - { name: service_collector, tag: smart_cache_request_policy, call: addPolicy}
- lazy: true
- smart_cache_response_policy:
- class: Drupal\Core\PageCache\ChainResponsePolicy
- tags:
- - { name: service_collector, tag: smart_cache_response_policy, call: addPolicy}
- lazy: true
- smart_cache_subscriber:
- class: Drupal\Core\EventSubscriber\SmartCacheSubscriber
- arguments: ['@cache_contexts_manager', '@cache.smart_cache_contexts', '@cache.smart_cache_html', '@smart_cache_request_policy', '@smart_cache_response_policy']
- tags:
- - { name: event_subscriber }
-
controller.form:
class: Drupal\Core\Controller\HtmlFormController
arguments: ['@controller_resolver', '@form_builder', '@class_resolver']
diff --git a/core/modules/page_cache/page_cache.info.yml b/core/modules/page_cache/page_cache.info.yml
index 4affed7..6999544 100644
--- a/core/modules/page_cache/page_cache.info.yml
+++ b/core/modules/page_cache/page_cache.info.yml
@@ -1,6 +1,6 @@
name: Internal Page Cache
type: module
-description: 'Caches pages for anonymous users. Works well for small to medium-sized websites.'
+description: 'Caches entire pages for anonymous users. Works well for small to medium-sized websites.'
package: Core
version: VERSION
core: 8.x
diff --git a/core/modules/page_cache/page_cache.module b/core/modules/page_cache/page_cache.module
index f4eb71b..cc00f29 100644
--- a/core/modules/page_cache/page_cache.module
+++ b/core/modules/page_cache/page_cache.module
@@ -21,7 +21,8 @@ function page_cache_help($route_name, RouteMatchInterface $route_match) {
$output .= '
';
$output .= '- ' . t('Speeding up your site') . '
';
$output .= '- ' . t('Pages requested by anonymous users are stored the first time they are requested and then are reused. Depending on your site configuration and the amount of your web traffic tied to anonymous visitors, the caching system may significantly increase the speed of your site.') . '
';
- $output .= '- ' . t('Pages are usually identical for all anonymous users, while they can be customized for each authenticated user. This is why pages can be cached for anonymous users, whereas they will have to be rebuilt for every authenticated user.') . '
';
+ $output .= '- ' . t('Pages are usually identical for all anonymous users, while they can be personalized for each authenticated user. This is why pages can be cached for anonymous users, whereas they will have to be rebuilt for every authenticated user.') . '
';
+ $output .= '- ' . t('For speeding up your site for authenticated users, see the online documentation for the Smart Cache module.', ['!smartcache-documentation' => 'https://www.drupal.org/documentation/modules/smart_cache']) . '';
$output .= '
- ' . t('Configuring the internal page cache') . '
';
$output .= '- ' . t('On the Performance page, you can configure how long browsers and proxies may cache pages; that setting is also respected by the Internal Page Cache module. There is no other configuration.', array('!cache-settings' => \Drupal::url('system.performance_settings'))) . '
';
$output .= '
';
diff --git a/core/modules/smart_cache/smart_cache.info.yml b/core/modules/smart_cache/smart_cache.info.yml
new file mode 100644
index 0000000..71778e1
--- /dev/null
+++ b/core/modules/smart_cache/smart_cache.info.yml
@@ -0,0 +1,6 @@
+name: Smart Cache
+type: module
+description: 'Caches the non-personalized parts of pages. Works well for websites of all sizes.'
+package: Core
+version: VERSION
+core: 8.x
diff --git a/core/modules/smart_cache/smart_cache.module b/core/modules/smart_cache/smart_cache.module
new file mode 100644
index 0000000..73341cd
--- /dev/null
+++ b/core/modules/smart_cache/smart_cache.module
@@ -0,0 +1,31 @@
+' . t('About') . '';
+ $output .= '' . t('The Smart Cache module caches the non-personalized parts of pages in the database. For more information, see the online documentation for the Smart Cache module.', ['!smartcache-documentation' => 'https://www.drupal.org/documentation/modules/smart_cache']) . '
';
+ $output .= '' . t('Uses') . '
';
+ $output .= '';
+ $output .= '- ' . t('Speeding up your site') . '
';
+ $output .= '- ' . t('Pages are stored the first time they are requested if they are safe to cache, and then are reused. Depending on your site configuration and the complexity of particular pages, Smart Cache may significantly increase the speed of your site, even for authenticated users.') . '
';
+ $output .= '- ' . t('Configuring the Smart Cache') . '
';
+ $output .= '- ' . t('Nothing needs to be configured — that is why it is smart!') . '
';
+ $output .= '- ' . t('(Every part of the page contains metadata that allows Smart Cache to figure this out on its own.)') . '
';
+ $output .= '
';
+
+ return $output;
+ }
+}
diff --git a/core/modules/smart_cache/smart_cache.services.yml b/core/modules/smart_cache/smart_cache.services.yml
new file mode 100644
index 0000000..6dbf512
--- /dev/null
+++ b/core/modules/smart_cache/smart_cache.services.yml
@@ -0,0 +1,44 @@
+services:
+ # Cache bins.
+ cache.smart_cache_contexts:
+ class: Drupal\Core\Cache\CacheBackendInterface
+ tags:
+ - { name: cache.bin }
+ factory: cache_factory:get
+ arguments: [smart_cache_contexts]
+ cache.smart_cache_html:
+ class: Drupal\Core\Cache\CacheBackendInterface
+ tags:
+ - { name: cache.bin }
+ factory: cache_factory:get
+ arguments: [smart_cache_html]
+
+ # Event subscriber.
+ smart_cache_subscriber:
+ class: Drupal\smart_cache\EventSubscriber\SmartCacheSubscriber
+ arguments: ['@cache_contexts_manager', '@cache.smart_cache_contexts', '@cache.smart_cache_html', '@smart_cache_request_policy', '@smart_cache_response_policy']
+ tags:
+ - { name: event_subscriber }
+
+ # Request & response policies.
+ smart_cache_request_policy:
+ class: Drupal\smart_cache\PageCache\RequestPolicy\DefaultRequestPolicy
+ tags:
+ - { name: service_collector, tag: smart_cache_request_policy, call: addPolicy}
+ lazy: true
+ smart_cache_response_policy:
+ class: Drupal\Core\PageCache\ChainResponsePolicy
+ tags:
+ - { name: service_collector, tag: smart_cache_response_policy, call: addPolicy}
+ lazy: true
+ smart_cache_deny_admin_routes:
+ class: Drupal\smart_cache\PageCache\ResponsePolicy\DenyAdminRoutes
+ arguments: ['@current_route_match']
+ public: false
+ tags:
+ - { name: smart_cache_response_policy }
+ smart_cache_deny_non_html_requests:
+ class: Drupal\smart_cache\PageCache\RequestPolicy\DenyNonHtmlRequests
+ public: false
+ tags:
+ - { name: smart_cache_request_policy }
diff --git a/core/lib/Drupal/Core/EventSubscriber/SmartCacheSubscriber.php b/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php
similarity index 98%
rename from core/lib/Drupal/Core/EventSubscriber/SmartCacheSubscriber.php
rename to core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php
index e642b7e..4b825a0 100644
--- a/core/lib/Drupal/Core/EventSubscriber/SmartCacheSubscriber.php
+++ b/core/modules/smart_cache/src/EventSubscriber/SmartCacheSubscriber.php
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\Core\EventSubscriber\SmartCacheSubscriber.
+ * Contains \Drupal\smart_cache\EventSubscriber\SmartCacheSubscriber.
*/
-namespace Drupal\Core\EventSubscriber;
+namespace Drupal\smart_cache\EventSubscriber;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;
diff --git a/core/lib/Drupal/Core/SmartCache/DefaultRequestPolicy.php b/core/modules/smart_cache/src/PageCache/RequestPolicy/DefaultRequestPolicy.php
similarity index 75%
rename from core/lib/Drupal/Core/SmartCache/DefaultRequestPolicy.php
rename to core/modules/smart_cache/src/PageCache/RequestPolicy/DefaultRequestPolicy.php
index 7a684dc..0651b8f 100644
--- a/core/lib/Drupal/Core/SmartCache/DefaultRequestPolicy.php
+++ b/core/modules/smart_cache/src/PageCache/RequestPolicy/DefaultRequestPolicy.php
@@ -2,15 +2,13 @@
/**
* @file
- * Contains \Drupal\Core\SmartCache\DefaultRequestPolicy.
+ * Contains \Drupal\smart_cache\PageCache\RequestPolicy\DefaultRequestPolicy.
*/
-namespace Drupal\Core\SmartCache;
+namespace Drupal\smart_cache\PageCache\RequestPolicy;
use Drupal\Core\PageCache\ChainRequestPolicy;
use Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod;
-use Drupal\Core\PageCache\RequestPolicy\NoAdminRoutes;
-use Drupal\Core\Routing\RouteMatchInterface;
/**
* The default SmartCache request policy.
diff --git a/core/lib/Drupal/Core/PageCache/RequestPolicy/DenyNonHtmlRequests.php b/core/modules/smart_cache/src/PageCache/RequestPolicy/DenyNonHtmlRequests.php
similarity index 77%
rename from core/lib/Drupal/Core/PageCache/RequestPolicy/DenyNonHtmlRequests.php
rename to core/modules/smart_cache/src/PageCache/RequestPolicy/DenyNonHtmlRequests.php
index 3880cf1..dfc5445 100644
--- a/core/lib/Drupal/Core/PageCache/RequestPolicy/DenyNonHtmlRequests.php
+++ b/core/modules/smart_cache/src/PageCache/RequestPolicy/DenyNonHtmlRequests.php
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\Core\PageCache\RequestPolicy\DenyNonHtmlRequests.
+ * Contains \Drupal\smart_cache\PageCache\RequestPolicy\DenyNonHtmlRequests.
*/
-namespace Drupal\Core\PageCache\RequestPolicy;
+namespace Drupal\smart_cache\PageCache\RequestPolicy;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
use Drupal\Core\PageCache\RequestPolicyInterface;
@@ -17,7 +17,7 @@
* The policy denies caching if the request has a request format other than HTML
* or when that is HTML, but additionally a wrapper format is specified.
*
- * @see \Drupal\Core\EventSubscriber\SmartCacheSubscriber
+ * @see \Drupal\smart_cache\EventSubscriber\SmartCacheSubscriber
*/
class DenyNonHtmlRequests implements RequestPolicyInterface {
diff --git a/core/lib/Drupal/Core/PageCache/ResponsePolicy/NoAdminRoutes.php b/core/modules/smart_cache/src/PageCache/ResponsePolicy/DenyAdminRoutes.php
similarity index 84%
rename from core/lib/Drupal/Core/PageCache/ResponsePolicy/NoAdminRoutes.php
rename to core/modules/smart_cache/src/PageCache/ResponsePolicy/DenyAdminRoutes.php
index 3c8dcdd..45485f5 100644
--- a/core/lib/Drupal/Core/PageCache/ResponsePolicy/NoAdminRoutes.php
+++ b/core/modules/smart_cache/src/PageCache/ResponsePolicy/DenyAdminRoutes.php
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\Core\PageCache\ResponsePolicy\NoAdminRoutes.
+ * Contains \Drupal\smart_cache\PageCache\ResponsePolicy\DenyAdminRoutes.
*/
-namespace Drupal\Core\PageCache\ResponsePolicy;
+namespace Drupal\smart_cache\PageCache\ResponsePolicy;
use Drupal\Core\PageCache\ResponsePolicyInterface;
use Drupal\Core\Routing\RouteMatchInterface;
@@ -17,7 +17,7 @@
*
* This policy rule denies caching of responses generated for admin routes.
*/
-class NoAdminRoutes implements ResponsePolicyInterface {
+class DenyAdminRoutes implements ResponsePolicyInterface {
/**
* The current route match.
diff --git a/core/modules/smart_cache/src/ProxyClass/PageCache/RequestPolicy/DefaultRequestPolicy.php b/core/modules/smart_cache/src/ProxyClass/PageCache/RequestPolicy/DefaultRequestPolicy.php
new file mode 100644
index 0000000..0aaa084
--- /dev/null
+++ b/core/modules/smart_cache/src/ProxyClass/PageCache/RequestPolicy/DefaultRequestPolicy.php
@@ -0,0 +1,92 @@
+container = $container;
+ $this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id;
+ }
+
+ /**
+ * Lazy loads the real service from the container.
+ *
+ * @return object
+ * Returns the constructed real service.
+ */
+ protected function lazyLoadItself()
+ {
+ if (!isset($this->service)) {
+ $this->service = $this->container->get($this->drupalProxyOriginalServiceId);
+ }
+
+ return $this->service;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function check(\Symfony\Component\HttpFoundation\Request $request)
+ {
+ return $this->lazyLoadItself()->check($request);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function addPolicy(\Drupal\Core\PageCache\RequestPolicyInterface $policy)
+ {
+ return $this->lazyLoadItself()->addPolicy($policy);
+ }
+
+ }
+
+}
diff --git a/core/modules/system/src/Tests/Cache/SmartCacheIntegrationTest.php b/core/modules/smart_cache/src/Tests/SmartCacheIntegrationTest.php
similarity index 96%
rename from core/modules/system/src/Tests/Cache/SmartCacheIntegrationTest.php
rename to core/modules/smart_cache/src/Tests/SmartCacheIntegrationTest.php
index ce9b3de..7a4e9e3 100644
--- a/core/modules/system/src/Tests/Cache/SmartCacheIntegrationTest.php
+++ b/core/modules/smart_cache/src/Tests/SmartCacheIntegrationTest.php
@@ -2,10 +2,10 @@
/**
* @file
- * Contains \Drupal\system\Tests\Cache\SmartCacheIntegrationTest.
+ * Contains \Drupal\smart_cache\Tests\SmartCacheIntegrationTest.
*/
-namespace Drupal\system\Tests\Cache;
+namespace Drupal\smart_cache\Tests;
use Drupal\Core\Cache\Cache;
use Drupal\Core\EventSubscriber\MainContentViewSubscriber;
@@ -16,11 +16,11 @@
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
/**
- * Enables the SmartCache and tests it in various scenarios.
+ * Enables the Smart Cache and tests it in various scenarios.
*
- * @group Cache
+ * @group smart_cache
*
- * @see \Drupal\Core\EventSubscriber\SmartCacheSubscriber
+ * @see \Drupal\smart_cache\EventSubscriber\SmartCacheSubscriber
*/
class SmartCacheIntegrationTest extends WebTestBase {
diff --git a/core/modules/system/tests/modules/smart_cache_test/smart_cache_test.info.yml b/core/modules/smart_cache/tests/smart_cache_test/smart_cache_test.info.yml
similarity index 100%
rename from core/modules/system/tests/modules/smart_cache_test/smart_cache_test.info.yml
rename to core/modules/smart_cache/tests/smart_cache_test/smart_cache_test.info.yml
diff --git a/core/modules/system/tests/modules/smart_cache_test/smart_cache_test.routing.yml b/core/modules/smart_cache/tests/smart_cache_test/smart_cache_test.routing.yml
similarity index 100%
rename from core/modules/system/tests/modules/smart_cache_test/smart_cache_test.routing.yml
rename to core/modules/smart_cache/tests/smart_cache_test/smart_cache_test.routing.yml
diff --git a/core/modules/system/tests/modules/smart_cache_test/src/SmartCacheTestController.php b/core/modules/smart_cache/tests/smart_cache_test/src/SmartCacheTestController.php
similarity index 100%
rename from core/modules/system/tests/modules/smart_cache_test/src/SmartCacheTestController.php
rename to core/modules/smart_cache/tests/smart_cache_test/src/SmartCacheTestController.php
diff --git a/core/profiles/minimal/minimal.info.yml b/core/profiles/minimal/minimal.info.yml
index 206b8e7..9c1d809 100644
--- a/core/profiles/minimal/minimal.info.yml
+++ b/core/profiles/minimal/minimal.info.yml
@@ -8,5 +8,6 @@ dependencies:
- block
- dblog
- page_cache
+ - smart_cache
themes:
- stark
diff --git a/core/profiles/standard/standard.info.yml b/core/profiles/standard/standard.info.yml
index a356ae8..b487f6d 100644
--- a/core/profiles/standard/standard.info.yml
+++ b/core/profiles/standard/standard.info.yml
@@ -26,6 +26,7 @@ dependencies:
- options
- path
- page_cache
+ - smart_cache
- taxonomy
- dblog
- search
diff --git a/core/profiles/testing/testing.info.yml b/core/profiles/testing/testing.info.yml
index 5ded376..8b04df4 100644
--- a/core/profiles/testing/testing.info.yml
+++ b/core/profiles/testing/testing.info.yml
@@ -5,9 +5,10 @@ version: VERSION
core: 8.x
hidden: true
dependencies:
- # Enable page_cache in testing, to ensure that as many tests as possible run
- # with page caching enabled.
+ # Enable page_cache and smart_cache in testing, to ensure that as many tests
+ # as possible run with anonymous page caching and SmartCache enabled.
- page_cache
+ - smart_cache
# @todo: Remove this in https://www.drupal.org/node/2352949
themes:
- classy
diff --git a/sites/example.settings.local.php b/sites/example.settings.local.php
index 34b4e19..e8cd909 100644
--- a/sites/example.settings.local.php
+++ b/sites/example.settings.local.php
@@ -59,6 +59,11 @@
$settings['cache']['bins']['render'] = 'cache.backend.null';
/**
+ * Disable SmartCache.
+ */
+$settings['cache']['bins']['smart_cache_html'] = 'cache.backend.null';
+
+/**
* Allow test modules and themes to be installed.
*
* Drupal ignores test modules and themes by default for performance reasons.