Skip to content

Instantly share code, notes, and snippets.

@omahm
Last active April 26, 2021 13:11
Show Gist options
  • Save omahm/cd990b5cdba637fe270ada0702717d9d to your computer and use it in GitHub Desktop.
Save omahm/cd990b5cdba637fe270ada0702717d9d to your computer and use it in GitHub Desktop.
Patch to enable cached Ajax responses.
diff --git a/core/lib/Drupal/Core/Cache/CacheableAjaxResponse.php b/core/lib/Drupal/Core/Cache/CacheableAjaxResponse.php
new file mode 100644
index 0000000000..996e674d8e
--- /dev/null
+++ b/core/lib/Drupal/Core/Cache/CacheableAjaxResponse.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Drupal\Core\Cache;
+
+use Drupal\Core\Ajax\AjaxResponse;
+
+/**
+ * A AjaxResponse that contains and can expose cacheability metadata.
+ *
+ * Supports Drupal's caching concepts: cache tags for invalidation and cache
+ * contexts for variations.
+ *
+ * @see \Drupal\Core\Cache\Cache
+ * @see \Drupal\Core\Cache\CacheableMetadata
+ * @see \Drupal\Core\Cache\CacheableResponseTrait
+ */
+class CacheableAjaxResponse extends AjaxResponse implements CacheableResponseInterface {
+
+ use CacheableResponseTrait;
+
+}
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment