Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
294
Merge Requests
294
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
7fcabc7a
Commit
7fcabc7a
authored
Oct 19, 2018
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2575105
by Berdir, catch, amateescu: Use cache collector for state (revert)
parent
4dfab43f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
48 additions
and
49 deletions
+48
-49
core/core.services.yml
core/core.services.yml
+1
-3
core/lib/Drupal/Core/Cache/MemoryBackend.php
core/lib/Drupal/Core/Cache/MemoryBackend.php
+1
-3
core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
...upal/Core/EventSubscriber/KernelDestructionSubscriber.php
+1
-4
core/lib/Drupal/Core/State/State.php
core/lib/Drupal/Core/State/State.php
+41
-29
core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php
...sts/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php
+1
-3
core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php
...sts/Drupal/KernelTests/Core/Routing/RouteProviderTest.php
+1
-2
core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
+1
-3
core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
+1
-2
No files found.
core/core.services.yml
View file @
7fcabc7a
...
...
@@ -439,9 +439,7 @@ services:
factory
:
Drupal\Core\Site\Settings::getInstance
state
:
class
:
Drupal\Core\State\State
arguments
:
[
'
@keyvalue'
,
'
@cache.bootstrap'
,
'
@lock'
]
tags
:
-
{
name
:
needs_destruction
}
arguments
:
[
'
@keyvalue'
]
queue
:
class
:
Drupal\Core\Queue\QueueFactory
arguments
:
[
'
@settings'
]
...
...
core/lib/Drupal/Core/Cache/MemoryBackend.php
View file @
7fcabc7a
...
...
@@ -157,9 +157,7 @@ public function invalidate($cid) {
*/
public
function
invalidateMultiple
(
array
$cids
)
{
foreach
(
$cids
as
$cid
)
{
if
(
isset
(
$this
->
cache
[
$cid
]))
{
$this
->
cache
[
$cid
]
->
expire
=
$this
->
getRequestTime
()
-
1
;
}
$this
->
cache
[
$cid
]
->
expire
=
$this
->
getRequestTime
()
-
1
;
}
}
...
...
core/lib/Drupal/Core/EventSubscriber/KernelDestructionSubscriber.php
View file @
7fcabc7a
...
...
@@ -60,10 +60,7 @@ public function onKernelTerminate(PostResponseEvent $event) {
* An array of event listener definitions.
*/
public
static
function
getSubscribedEvents
()
{
// Run this subscriber after others as those might use services that need
// to be terminated as well or run code that needs to run before
// termination.
$events
[
KernelEvents
::
TERMINATE
][]
=
[
'onKernelTerminate'
,
-
100
];
$events
[
KernelEvents
::
TERMINATE
][]
=
[
'onKernelTerminate'
,
100
];
return
$events
;
}
...
...
core/lib/Drupal/Core/State/State.php
View file @
7fcabc7a
...
...
@@ -2,15 +2,12 @@
namespace
Drupal\Core\State
;
use
Drupal\Core\Cache\CacheBackendInterface
;
use
Drupal\Core\Cache\CacheCollector
;
use
Drupal\Core\KeyValueStore\KeyValueFactoryInterface
;
use
Drupal\Core\Lock\LockBackendInterface
;
/**
* Provides the state system using a key value store.
*/
class
State
extends
CacheCollector
implements
StateInterface
{
class
State
implements
StateInterface
{
/**
* The key value store to use.
...
...
@@ -19,18 +16,20 @@ class State extends CacheCollector implements StateInterface {
*/
protected
$keyValueStore
;
/**
* Static state cache.
*
* @var array
*/
protected
$cache
=
[];
/**
* Constructs a State object.
*
* @param \Drupal\Core\KeyValueStore\KeyValueFactoryInterface $key_value_factory
* The key value store to use.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend.
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* The lock backend.
*/
public
function
__construct
(
KeyValueFactoryInterface
$key_value_factory
,
CacheBackendInterface
$cache
,
LockBackendInterface
$lock
)
{
parent
::
__construct
(
'state'
,
$cache
,
$lock
);
public
function
__construct
(
KeyValueFactoryInterface
$key_value_factory
)
{
$this
->
keyValueStore
=
$key_value_factory
->
get
(
'state'
);
}
...
...
@@ -38,18 +37,8 @@ public function __construct(KeyValueFactoryInterface $key_value_factory, CacheBa
* {@inheritdoc}
*/
public
function
get
(
$key
,
$default
=
NULL
)
{
$value
=
parent
::
get
(
$key
);
return
$value
!==
NULL
?
$value
:
$default
;
}
/**
* {@inheritdoc}
*/
protected
function
resolveCacheMiss
(
$key
)
{
$value
=
$this
->
keyValueStore
->
get
(
$key
);
$this
->
storage
[
$key
]
=
$value
;
$this
->
persist
(
$key
);
return
$value
;
$values
=
$this
->
getMultiple
([
$key
]);
return
isset
(
$values
[
$key
])
?
$values
[
$key
]
:
$default
;
}
/**
...
...
@@ -57,9 +46,33 @@ protected function resolveCacheMiss($key) {
*/
public
function
getMultiple
(
array
$keys
)
{
$values
=
[];
$load
=
[];
foreach
(
$keys
as
$key
)
{
$values
[
$key
]
=
$this
->
get
(
$key
);
// Check if we have a value in the cache.
if
(
isset
(
$this
->
cache
[
$key
]))
{
$values
[
$key
]
=
$this
->
cache
[
$key
];
}
// Load the value if we don't have an explicit NULL value.
elseif
(
!
array_key_exists
(
$key
,
$this
->
cache
))
{
$load
[]
=
$key
;
}
}
if
(
$load
)
{
$loaded_values
=
$this
->
keyValueStore
->
getMultiple
(
$load
);
foreach
(
$load
as
$key
)
{
// If we find a value, even one that is NULL, add it to the cache and
// return it.
if
(
isset
(
$loaded_values
[
$key
])
||
array_key_exists
(
$key
,
$loaded_values
))
{
$values
[
$key
]
=
$loaded_values
[
$key
];
$this
->
cache
[
$key
]
=
$loaded_values
[
$key
];
}
else
{
$this
->
cache
[
$key
]
=
NULL
;
}
}
}
return
$values
;
}
...
...
@@ -67,7 +80,7 @@ public function getMultiple(array $keys) {
* {@inheritdoc}
*/
public
function
set
(
$key
,
$value
)
{
parent
::
set
(
$key
,
$value
)
;
$this
->
cache
[
$key
]
=
$value
;
$this
->
keyValueStore
->
set
(
$key
,
$value
);
}
...
...
@@ -76,7 +89,7 @@ public function set($key, $value) {
*/
public
function
setMultiple
(
array
$data
)
{
foreach
(
$data
as
$key
=>
$value
)
{
parent
::
set
(
$key
,
$value
)
;
$this
->
cache
[
$key
]
=
$value
;
}
$this
->
keyValueStore
->
setMultiple
(
$data
);
}
...
...
@@ -85,8 +98,7 @@ public function setMultiple(array $data) {
* {@inheritdoc}
*/
public
function
delete
(
$key
)
{
parent
::
delete
(
$key
);
$this
->
keyValueStore
->
delete
(
$key
);
$this
->
deleteMultiple
([
$key
]);
}
/**
...
...
@@ -94,7 +106,7 @@ public function delete($key) {
*/
public
function
deleteMultiple
(
array
$keys
)
{
foreach
(
$keys
as
$key
)
{
parent
::
delete
(
$key
);
unset
(
$this
->
cache
[
$key
]
);
}
$this
->
keyValueStore
->
deleteMultiple
(
$keys
);
}
...
...
@@ -103,7 +115,7 @@ public function deleteMultiple(array $keys) {
* {@inheritdoc}
*/
public
function
resetCache
()
{
$this
->
c
lear
()
;
$this
->
c
ache
=
[]
;
}
}
core/tests/Drupal/KernelTests/Core/Routing/MatcherDumperTest.php
View file @
7fcabc7a
...
...
@@ -2,9 +2,7 @@
namespace
Drupal\KernelTests\Core\Routing
;
use
Drupal\Core\Cache\MemoryBackend
;
use
Drupal\Core\KeyValueStore\KeyValueMemoryFactory
;
use
Drupal\Core\Lock\NullLockBackend
;
use
Drupal\Core\State\State
;
use
Drupal\KernelTests\KernelTestBase
;
use
Symfony\Component\Routing\Route
;
...
...
@@ -38,7 +36,7 @@ protected function setUp() {
parent
::
setUp
();
$this
->
fixtures
=
new
RoutingFixtures
();
$this
->
state
=
new
State
(
new
KeyValueMemoryFactory
()
,
new
MemoryBackend
(
'test'
),
new
NullLockBackend
()
);
$this
->
state
=
new
State
(
new
KeyValueMemoryFactory
());
}
/**
...
...
core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php
View file @
7fcabc7a
...
...
@@ -12,7 +12,6 @@
use
Drupal\Core\Database\Database
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
use
Drupal\Core\KeyValueStore\KeyValueMemoryFactory
;
use
Drupal\Core\Lock\NullLockBackend
;
use
Drupal\Core\Path\CurrentPathStack
;
use
Drupal\Core\Routing\MatcherDumper
;
use
Drupal\Core\Routing\RouteProvider
;
...
...
@@ -84,7 +83,7 @@ class RouteProviderTest extends KernelTestBase {
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
fixtures
=
new
RoutingFixtures
();
$this
->
state
=
new
State
(
new
KeyValueMemoryFactory
()
,
new
MemoryBackend
(
'test'
),
new
NullLockBackend
()
);
$this
->
state
=
new
State
(
new
KeyValueMemoryFactory
());
$this
->
currentPath
=
new
CurrentPathStack
(
new
RequestStack
());
$this
->
cache
=
new
MemoryBackend
();
$this
->
pathProcessor
=
\
Drupal
::
service
(
'path_processor_manager'
);
...
...
core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php
View file @
7fcabc7a
...
...
@@ -7,12 +7,10 @@
namespace
Drupal\Tests\Core\Extension
;
use
Drupal\Core\Cache\MemoryBackend
;
use
Drupal\Core\Extension\Extension
;
use
Drupal\Core\Extension\InfoParser
;
use
Drupal\Core\Extension\ThemeHandler
;
use
Drupal\Core\KeyValueStore\KeyValueMemoryFactory
;
use
Drupal\Core\Lock\NullLockBackend
;
use
Drupal\Core\State\State
;
use
Drupal\Tests\UnitTestCase
;
...
...
@@ -80,7 +78,7 @@ protected function setUp() {
],
]);
$this
->
moduleHandler
=
$this
->
getMock
(
'Drupal\Core\Extension\ModuleHandlerInterface'
);
$this
->
state
=
new
State
(
new
KeyValueMemoryFactory
()
,
new
MemoryBackend
(
'test'
),
new
NullLockBackend
()
);
$this
->
state
=
new
State
(
new
KeyValueMemoryFactory
());
$this
->
infoParser
=
$this
->
getMock
(
'Drupal\Core\Extension\InfoParserInterface'
);
$this
->
extensionDiscovery
=
$this
->
getMockBuilder
(
'Drupal\Core\Extension\ExtensionDiscovery'
)
->
disableOriginalConstructor
()
...
...
core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
View file @
7fcabc7a
...
...
@@ -9,7 +9,6 @@
use
Drupal\Core\Cache\MemoryBackend
;
use
Drupal\Core\KeyValueStore\KeyValueMemoryFactory
;
use
Drupal\Core\Lock\NullLockBackend
;
use
Drupal\Core\State\State
;
use
Drupal\Core\Cache\Cache
;
...
...
@@ -539,7 +538,7 @@ public function testBubblingWithPrerender($test_element) {
$this
->
setupMemoryCache
();
// Mock the State service.
$memory_state
=
new
State
(
new
KeyValueMemoryFactory
()
,
new
MemoryBackend
(
'test'
),
new
NullLockBackend
()
);
$memory_state
=
new
State
(
new
KeyValueMemoryFactory
());
\
Drupal
::
getContainer
()
->
set
(
'state'
,
$memory_state
);
$this
->
controllerResolver
->
expects
(
$this
->
any
())
->
method
(
'getControllerFromDefinition'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment