When EntityManager was written, CacheDecorator did not support cache tags, so it implements its own caching.

Now that CacheDecorator does support cache tags, it should likely switch back.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Active » Needs review
FileSize
4.41 KB

Since the CacheDecorator also provides static caching, we can simplify entity_get_info() to the point where it shouldn't be called anymore.

yched’s picture

Status: Needs review » Needs work

Big, big +1.

However :

@@ -48,11 +41,10 @@ function entity_get_info($entity_type = NULL) {
  * Resets the cached information about entity types.
  */
 function entity_info_cache_clear() {
  (...)
   // Clear all languages.
-  cache()->deleteTags(array('entity_info' => TRUE));
+  drupal_container()->get('plugin.manager.entity')->clearCachedDefinitions();
 }

EntityManager::clearCachedDefinitions() will only clear the data for the current language, won't it ?
(aka #1722882-41: Plugin CacheDecorator caches globally, ignores request context, and does not specify tags for cache items)

2 days to next Drupal core point release.

tim.plunkett’s picture

CacheDecorator::clearCachedDefinitions() will work for all languages if you use cache tags, which we do, and #1893818: Plugin discovery caches of blocks are not cleared for all languages does not. We're good here :)

tim.plunkett’s picture

Status: Needs work » Needs review
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.
I was a bit confused that the cache tags are declared as array('entity_info' => TRUE), while the issue in #3 does array('block'). I *think* both work, but easier way I think the method here seems to be more standard as cache tags were primarily introduced for the array('node' => array(1, 2, 3)) use-case.

yched’s picture

@tim : Ah, right, skipped that. Too long since I've been able to crack my D8 open :-/
(+ sorry about status change, was not intentional)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, entity-1892462-1.patch, failed testing.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

Debugging. The main failing test is the one for this caching specifically, so that's good to see we have coverage :)

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
1.53 KB
5.93 KB

EntityTranslationSettingsTest was calling drupal_static_reset() when all it needed was entity_info_cache_clear(), and I added a call to clear the static cache of EntityManager in drupal_flush_all_caches() under the section intended for just that!

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
FileSize
741 bytes
6.13 KB

Actually, we should do this, so that it's clear what is actually happening, and it's clearer what to convert to.

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

Assuming it passes tests, this looks pretty sane to me.

RTBC

sun’s picture

Priority: Normal » Major
Status: Reviewed & tested by the community » Needs review

Bumping to major, since the drupal_static() in entity_get_info() actually causes a mismatch between actual discovery info and statically cached info at runtime, which took me some hours of debugging to figure out in #1901380: [Block]PluginManager repetitively triggers full-stack Annotation parsing on a plugin instance ID miss

The changes here seem to be identical with regard to the EntityManager, so let's make sure to get this in ASAP.

Only a few remarks:

(If anything I'm saying is not the case, then we need crystal clear comments that explain why the respective code is still needed.)

+++ b/core/includes/common.inc
@@ -6430,7 +6430,7 @@ function drupal_flush_all_caches() {
   // Clear all non-drupal_static() static caches.
-  // None currently; kept if any static caches need to be reset in the future.
+  drupal_container()->get('plugin.manager.entity')->clearCachedDefinitions();

This should not be necessary. All caches are flushed before that call already, and the entire kernel/container is rebuilt a few lines below.

+++ b/core/includes/entity.inc
@@ -48,11 +39,10 @@ function entity_get_info($entity_type = NULL) {
 function entity_info_cache_clear() {
-  drupal_static_reset('entity_get_info');
...
   // Clear all languages.
-  cache()->deleteTags(array('entity_info' => TRUE));
+  drupal_container()->get('plugin.manager.entity')->clearCachedDefinitions();

Likewise, this should simply vanish.

+++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php
@@ -115,7 +115,7 @@ protected function assertSettings($entity_type, $bundle, $enabled, $edit) {
-    drupal_static_reset();
+    entity_info_cache_clear();

Tests simply call into $this->rebuildContainer(). This one might still need the static reset for the bundles/view-modes though.

Status: Needs review » Needs work

The last submitted patch, entity-1892462-10.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community

All of the calls to clearCachedDefinitions() are for the static caching provided by CacheDecorator, not the cache backend caching. Trust me, they're needed, see the failures in #1.

If we want to have a separate call to clear the static caches of CacheDecorator, that's fine, but in HEAD we only have clearCachedDefinitions().

sun’s picture

Status: Reviewed & tested by the community » Needs review

Let's document that then.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
6.75 KB
1.02 KB

Okay, documented. I think the above confusion was because sun thought #1872522: Compiled data in PHP storage is cleared too late in drupal_flush_all_caches() had gone in already.

sun’s picture

Thanks, works for me! Agreed with RTBC. Time to get rid of that static! :)

Hopefully it comes back green.

Status: Reviewed & tested by the community » Needs work
Issue tags: -Plugin system

The last submitted patch, entity-1892462-16.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: +Plugin system

#16: entity-1892462-16.patch queued for re-testing.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Random failure in FilledMinimalUpgradePathTest.

catch’s picture

Status: Reviewed & tested by the community » Fixed

That's very nice. Committed/pushed to 8.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

podarok’s picture

Title: EntityManager should use the CacheDecorator » Change record: EntityManager should use the CacheDecorator
Category: task » bug
Priority: Major » Critical
Status: Closed (fixed) » Needs review

this one filled with change record due to @depretaced function
needs review

ParisLiakos’s picture

Category: bug » task

still a task, right?

tim.plunkett’s picture

Title: Change record: EntityManager should use the CacheDecorator » EntityManager should use the CacheDecorator
Priority: Critical » Major
Status: Needs review » Closed (fixed)

This is fine.