Repository: plone/plone.restapi (language: python)

Issue:
Apply a cache ruleset to the @querystring-search endpoint



Discussion / hints:

Fix patch:
diff --git a/news/1626.feat b/news/1626.feat
new file mode 100644
index 0000000000..27422e2ea8
--- /dev/null
+++ b/news/1626.feat
@@ -0,0 +1,2 @@
+Apply a cache ruleset to the /@querystring-search endpoint.
+[ericof]
\ No newline at end of file
diff --git a/src/plone/restapi/services/querystringsearch/configure.zcml b/src/plone/restapi/services/querystringsearch/configure.zcml
index 899f1f1156..21ad182d55 100644
--- a/src/plone/restapi/services/querystringsearch/configure.zcml
+++ b/src/plone/restapi/services/querystringsearch/configure.zcml
@@ -1,6 +1,8 @@
 <configure
     xmlns="http://namespaces.zope.org/zope"
+    xmlns:cache="http://namespaces.zope.org/cache"
     xmlns:plone="http://namespaces.plone.org/plone"
+    xmlns:zcml="http://namespaces.zope.org/zcml"
     >
 
   <plone:service
@@ -34,4 +36,11 @@
       permission="zope2.View"
       name="@querystring-search"
       />
+
+  <cache:ruleset
+      for=".get.QuerystringSearchGet"
+      ruleset="plone.content.dynamic"
+      zcml:condition="have plone-app-caching-3"
+      />
+
 </configure>


Test patch:
diff --git a/src/plone/restapi/tests/test_caching.py b/src/plone/restapi/tests/test_caching.py
index 060ae3566c..9ba9b79fcd 100644
--- a/src/plone/restapi/tests/test_caching.py
+++ b/src/plone/restapi/tests/test_caching.py
@@ -112,6 +112,18 @@ def test_restapi_querystring(self):
             response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
         )
 
+    def test_restapi_querystring_search(self):
+        # plone.content.dynamic for
+        #  plone.restapi.services.querystringsearch.get.QuerystringSearchGet
+        response = self.api_session.get(
+            "/@querystring-search?query=%7B%22query%22%3A%20%5B%7B%22i%22%3A%20%22portal_type%22%2C%20%22o%22%3A%20%22plone.app.querystring.operation.selection.any%22%2C%20%22v%22%3A%20%5B%22Document%22%5D%7D%5D%2C%20%22b_size%22%3A%201%7D"
+        )
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
+        self.assertEqual(
+            response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
+        )
+
     def test_restapi_search(self):
         # plone.content.dynamic for plone.restapi.services.search.get.SearchGet
         response = self.api_session.get("/@search")
@@ -222,6 +234,18 @@ def test_restapi_querystring(self):
             response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
         )
 
+    def test_restapi_querystring_search(self):
+        # plone.content.dynamic for
+        #  plone.restapi.services.querystringsearch.get.QuerystringSearchGet
+        response = self.api_session.get(
+            "/@querystring-search?query=%7B%22query%22%3A%20%5B%7B%22i%22%3A%20%22portal_type%22%2C%20%22o%22%3A%20%22plone.app.querystring.operation.selection.any%22%2C%20%22v%22%3A%20%5B%22Document%22%5D%7D%5D%2C%20%22b_size%22%3A%201%7D"
+        )
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.headers["X-Cache-Rule"], "plone.content.dynamic")
+        self.assertEqual(
+            response.headers["X-Cache-Operation"], "plone.app.caching.terseCaching"
+        )
+
     def test_restapi_search(self):
         # plone.content.dynamic for plone.restapi.services.search.get.SearchGet
         response = self.api_session.get("/@search")