From cc7301a66c29ba3fc68ecb90e554a7b9650c152d Mon Sep 17 00:00:00 2001
From: Hendrik Grahl <hendrik.grahl@liip.ch>
Date: Sat, 6 Jul 2019 11:21:25 +0200
Subject: [PATCH] Limit entity in-memory cache.

---
 core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php b/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php
index ba70b01..6b80ab4 100644
--- a/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php
+++ b/core/lib/Drupal/Core/Cache/MemoryCache/MemoryCache.php
@@ -49,6 +49,11 @@ protected function prepareItem($cache, $allow_invalid = FALSE) {
    */
   public function set($cid, $data, $expire = MemoryCacheInterface::CACHE_PERMANENT, array $tags = []) {
     assert(Inspector::assertAllStrings($tags), 'Cache tags must be strings.');
+
+    if (count($this->cache) > 5000) {
+      $this->reset();
+    }
+
     $tags = array_unique($tags);
 
     $this->cache[$cid] = (object) [
-- 
2.21.0

