This is an automated email from the ASF dual-hosted git repository.
snoopdave pushed a commit to branch roller-6.1.x
in repository https://gitbox.apache.org/repos/asf/roller.git
The following commit(s) were added to refs/heads/roller-6.1.x by this push:
new 1fc99c0aa Key the front page weblog's custom pages by page name and
tags too (#274)
1fc99c0aa is described below
commit 1fc99c0aa668e2b600f81ea8118b4f6c80819462
Author: Matt Raible <[email protected]>
AuthorDate: Sun Nov 15 10:26:35 2026 -0700
Key the front page weblog's custom pages by page name and tags too (#274)
#271 fixed WeblogPageCache.generateKey, but PageServlet uses
SiteWideCache.generateKey for the site-wide weblog, and that still had the old
logic. There, a custom page that names an entry shared the entry's own key, and
tags given to a custom page weren't in the key, so one could be served in place
of another. SiteWideCache now builds those parts of the key the same way.
WeblogPageCacheKeyTest now runs each case against both caches. Three of its
four cases fail on roller-6.1.x for the site-wide cache.
---
.../ui/rendering/util/cache/SiteWideCache.java | 23 +++++++----
.../util/cache/WeblogPageCacheKeyTest.java | 45 ++++++++++++++--------
2 files changed, 43 insertions(+), 25 deletions(-)
diff --git
a/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
b/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
index 671f6c18a..74e01893b 100644
---
a/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
+++
b/app/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/SiteWideCache.java
@@ -202,6 +202,12 @@ public final class SiteWideCache implements CacheHandler {
// may contain spaces or other bad chars
String anchor = URLEncoder.encode(pageRequest.getWeblogAnchor(),
StandardCharsets.UTF_8);
key.append("/entry/").append(anchor);
+
+ // a custom page can also name an entry, and must not share the
+ // entry's own key
+ if(pageRequest.getWeblogPageName() != null) {
+ key.append("/page/").append(pageRequest.getWeblogPageName());
+ }
} else {
if(pageRequest.getWeblogPageName() != null) {
@@ -217,14 +223,15 @@ public final class SiteWideCache implements CacheHandler {
String cat =
URLEncoder.encode(pageRequest.getWeblogCategoryName(), StandardCharsets.UTF_8);
key.append('/').append(cat);
}
-
- if("tags".equals(pageRequest.getContext())) {
- if(pageRequest.getTags() != null &&
!pageRequest.getTags().isEmpty()) {
- String[] tags = pageRequest.getTags().toArray(new
String[0]);
- Arrays.sort(tags);
-
key.append("/tags/").append(Utilities.stringArrayToString(tags,"+"));
- }
- }
+ }
+
+ // tags come from the path in the tags context, or from a query
+ // parameter on a custom page; either way they change the page
+ if(pageRequest.getTags() != null && !pageRequest.getTags().isEmpty()) {
+ String[] tags = pageRequest.getTags().toArray(new String[0]);
+ Arrays.sort(tags);
+ String joined = Utilities.stringArrayToString(tags, "+");
+ key.append("/tags/").append(URLEncoder.encode(joined,
StandardCharsets.UTF_8));
}
if(pageRequest.getLocale() != null) {
diff --git
a/app/src/test/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogPageCacheKeyTest.java
b/app/src/test/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogPageCacheKeyTest.java
index cd1700a27..4e47cbcf9 100644
---
a/app/src/test/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogPageCacheKeyTest.java
+++
b/app/src/test/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogPageCacheKeyTest.java
@@ -19,6 +19,8 @@
package org.apache.roller.weblogger.ui.rendering.util.cache;
import java.util.Arrays;
+import java.util.List;
+import java.util.function.Function;
import org.apache.roller.weblogger.ui.rendering.util.WeblogPageRequest;
import org.junit.jupiter.api.Test;
@@ -28,7 +30,8 @@ import static
org.junit.jupiter.api.Assertions.assertNotEquals;
/**
* Requests that can render different content must get different page cache
- * keys.
+ * keys, in the weblog page cache and in the site-wide cache that the front
+ * page weblog uses.
*/
public class WeblogPageCacheKeyTest {
@@ -45,36 +48,44 @@ public class WeblogPageCacheKeyTest {
return request;
}
- private static String key(WeblogPageRequest request) {
- return WeblogPageCache.getInstance().generateKey(request);
- }
+ private static final List<Function<WeblogPageRequest, String>> CACHES =
List.of(
+ request -> WeblogPageCache.getInstance().generateKey(request),
+ request -> SiteWideCache.getInstance().generateKey(request));
@Test
public void customPageNamingAnEntryHasItsOwnKey() {
- String permalink = key(request("entry", "first-post", null));
- String customPage = key(request("page", "first-post", "archives"));
- assertNotEquals(permalink, customPage);
+ for (Function<WeblogPageRequest, String> key : CACHES) {
+ String permalink = key.apply(request("entry", "first-post", null));
+ String customPage = key.apply(request("page", "first-post",
"archives"));
+ assertNotEquals(permalink, customPage);
+ }
}
@Test
public void tagsOnACustomPageAreInTheKey() {
- String plain = key(request("page", null, "archives"));
- String tagged = key(request("page", null, "archives", "java"));
- String otherTag = key(request("page", null, "archives", "roller"));
- assertNotEquals(plain, tagged);
- assertNotEquals(tagged, otherTag);
+ for (Function<WeblogPageRequest, String> key : CACHES) {
+ String plain = key.apply(request("page", null, "archives"));
+ String tagged = key.apply(request("page", null, "archives",
"java"));
+ String otherTag = key.apply(request("page", null, "archives",
"roller"));
+ assertNotEquals(plain, tagged);
+ assertNotEquals(tagged, otherTag);
+ }
}
@Test
public void tagsOnACustomPageNamingAnEntryAreInTheKey() {
- String untagged = key(request("page", "first-post", "archives"));
- String tagged = key(request("page", "first-post", "archives", "java"));
- assertNotEquals(untagged, tagged);
+ for (Function<WeblogPageRequest, String> key : CACHES) {
+ String untagged = key.apply(request("page", "first-post",
"archives"));
+ String tagged = key.apply(request("page", "first-post",
"archives", "java"));
+ assertNotEquals(untagged, tagged);
+ }
}
@Test
public void tagOrderDoesNotChangeTheKey() {
- assertEquals(key(request("tags", null, null, "java", "roller")),
- key(request("tags", null, null, "roller", "java")));
+ for (Function<WeblogPageRequest, String> key : CACHES) {
+ assertEquals(key.apply(request("tags", null, null, "java",
"roller")),
+ key.apply(request("tags", null, null, "roller", "java")));
+ }
}
}