Skip to content

Commit

Permalink
Apply a cache ruleset to the /@querystring-search endpoint (#1627)
Browse files Browse the repository at this point in the history
* Apply a cache ruleset to the /@querystring-search endpoint

* Fix translation
  • Loading branch information
ericof committed Apr 19, 2023
1 parent 730e76f commit a2729ac
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/1626.feat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Apply a cache ruleset to the /@querystring-search endpoint.
[ericof]
9 changes: 9 additions & 0 deletions src/plone/restapi/services/querystringsearch/configure.zcml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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>
24 changes: 24 additions & 0 deletions src/plone/restapi/tests/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a2729ac

Please sign in to comment.