Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

urls: Add /flush_caches URL to remove all the server-side cache.

Riken Shah1d23d13ef581
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py
index 77e16153c4a..c783891c9dc 100644
--- a/zerver/lib/test_helpers.py
+++ b/zerver/lib/test_helpers.py
@@ -495,6 +495,7 @@ def write_instrumentation_reports(full_suite: bool, include_webhooks: bool) -> N
"docs/(?P<path>.+)",
"casper/(?P<path>.+)",
"static/(?P<path>.+)",
+ "flush_caches",
*(webhook.url for webhook in WEBHOOK_INTEGRATIONS if not include_webhooks),
}
diff --git a/zerver/views/development/cache.py b/zerver/views/development/cache.py
new file mode 100644
index 00000000000..2d9f70932e7
--- /dev/null
+++ b/zerver/views/development/cache.py
@@ -0,0 +1,17 @@
+import os
+
+from django.http import HttpRequest, HttpResponse
+
+from zerver.lib.cache import get_cache_backend
+from zerver.lib.response import json_success
+from zerver.models import clear_client_cache, flush_per_request_caches
+
+ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../../")
+
+# This is used only by the Puppeteer Tests to clear all the cache after each run.
+def remove_caches(request: HttpRequest) -> HttpResponse:
+ cache = get_cache_backend(None)
+ cache.clear()
+ clear_client_cache()
+ flush_per_request_caches()
+ return json_success()
diff --git a/zproject/dev_urls.py b/zproject/dev_urls.py
index c885dc281d4..7ed850a878e 100644
--- a/zproject/dev_urls.py
+++ b/zproject/dev_urls.py
@@ -10,6 +10,7 @@ from django.views.generic import TemplateView
from django.views.static import serve
from zerver.views.auth import config_error, login_page
+from zerver.views.development.cache import remove_caches
from zerver.views.development.email_log import clear_emails, email_page, generate_all_emails
from zerver.views.development.integrations import (
check_send_webhook_fixture_message,
@@ -73,6 +74,8 @@ urls = [
path("devtools/integrations/<integration_name>/fixtures", get_fixtures),
path("config-error/<error_category_name>", config_error, name="config_error"),
path("config-error/remoteuser/<error_category_name>", config_error),
+ # Special endpoint to remove all the server-side caches.
+ path("flush_caches", remove_caches),
]
# Serve static assets via the Django server