You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2020/10/22 14:14:27 UTC

[wicket] branch master updated: WICKET-6845 by default session cache should not serialize

This is an automated email from the ASF dual-hosted git repository.

svenmeier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new f9f960e  WICKET-6845 by default session cache should not serialize
f9f960e is described below

commit f9f960e3e07fa1499a82f9686d9c87ed9dae597f
Author: Sven Meier <sv...@apache.org>
AuthorDate: Thu Oct 22 16:11:32 2020 +0200

    WICKET-6845 by default session cache should not serialize
    
    If the session gets serialized, pages can be acquired from persistent store again.
    
    Added comments for prevention of serialization loop (if InSessionPageStore does indeed
    serialize).
    Corrected JavaDoc of DefaultPageManagerProvider.
---
 .../org/apache/wicket/DefaultPageManagerProvider.java  | 18 +++++++++++-------
 .../apache/wicket/pageStore/InSessionPageStore.java    | 11 +++++++++--
 .../apache/wicket/DefaultPageManagerProviderTest.java  |  3 +++
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java b/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java
index c3d9064..0b44073 100644
--- a/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java
+++ b/wicket-core/src/main/java/org/apache/wicket/DefaultPageManagerProvider.java
@@ -43,18 +43,20 @@ import org.apache.wicket.util.lang.Bytes;
  * A provider of a {@link PageManager} managing @link IManageablePage}s with a default chain of {@link IPageStore}s:
  * <ol>
  * <li>{@link RequestPageStore} keeping pages until end of the request</li>
- * <li>{@link InSessionPageStore} caching the last accessed page in the session</li>
- * <li>{@link AsynchronousPageStore} moving storage of pages to an asynchronous worker thread (enabled by default with {@link StoreSettings#isAsynchronous()})</li>
+ * <li>{@link CachingPageStore} caching with an ...</li>
+ * <li>{@link InSessionPageStore} keeping the last accessed page in the session</li>
  * <li>{@link SerializingPageStore} serializing all pages (so they are available for back-button)</li>
+ * <li>{@link AsynchronousPageStore} moving storage of pages to an asynchronous worker thread (enabled by default with {@link StoreSettings#isAsynchronous()})</li>
  * <li>{@link CryptingPageStore} encrypting all pages (disabled by default in {@link StoreSettings#isEncrypted()})</li>
  * <li>{@link DiskPageStore} persisting all pages, configured according to {@link StoreSettings}</li>
  * </ol>
  * An alternative chain with all pages held in-memory could be:
  * <ol>
- * <li>{@link RequestPageStore} caching pages until end of the request</li>
+ * <li>{@link RequestPageStore} keeping pages until end of the request</li>
+ * <li>{@link CachingPageStore} caching with an ...</li>
  * <li>{@link InSessionPageStore} keeping the last accessed page in the session</li>
- * <li>{@link AsynchronousPageStore} moving storage of pages to a worker thread</li>
  * <li>{@link SerializingPageStore} serializing all pages (so they are available for back-button)</li>
+ * <li>{@link AsynchronousPageStore} moving storage of pages to a worker thread</li>
  * <li>{@link InMemoryPageStore} keeping all pages in memory</li>
  * </ol>
  * ... or if all pages should be kept in the session only, without any serialization (no back-button
@@ -73,7 +75,6 @@ import org.apache.wicket.util.lang.Bytes;
  * Other stores be may inserted ad libitum, e.g.
  * <ul>
  * <li>{@link NoopPageStore} discards all pages</li>
- * <li>{@link CachingPageStore} uses a page store as a cache in front of another store</li>
  * <li>{@link GroupingPageStore} groups pages, e.g. to limit storage size on a per-group basis</li>
  * <li>{@link FilePageStore} as an alternative to the trusted {@link DiskPageStore}</li>
  * <li>other implementations from <a href="https://github.com/wicketstuff/core/tree/master/datastores-parent">wicketstuff-datastores</a></li>
@@ -137,13 +138,16 @@ public class DefaultPageManagerProvider implements IPageManagerProvider
 	}
 
 	/**
-	 * Cache last page in the session for fast access.
+	 * Cache last page non-serialized in the session for fast access.
+	 * <p>
+	 * On session serialization the cached page will be dropped and re-acquired from
+	 * a persistent store. 
 	 * 
 	 * @see InSessionPageStore
 	 */
 	protected IPageStore newCachingStore(IPageStore pageStore)
 	{
-		return new CachingPageStore(pageStore, new InSessionPageStore(1, getSerializer()));
+		return new CachingPageStore(pageStore, new InSessionPageStore(1));
 	}
 
 	/**
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java
index 87cb701..5aaf563 100644
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/InSessionPageStore.java
@@ -55,8 +55,8 @@ public class InSessionPageStore implements IPageStore
 	/**
 	 * Keep {@code maxPages} persistent in each session.
 	 * <p>
-	 * All pages added to this store <em>must</em> be {@code SerializedPage}s. You can achieve this
-	 * by letting a {@link SerializingPageStore} delegate to this store.
+	 * Any page added to this store <em>not</em> being a {@code SerializedPage} will be dropped
+	 * on serialization of the session.
 	 * 
 	 * @param maxPages
 	 *            maximum pages to keep in session
@@ -278,15 +278,22 @@ public class InSessionPageStore implements IPageStore
 
 				if ((page instanceof SerializedPage) == false)
 				{
+					// remove if not already serialized
 					pages.remove(p);
+					
 					if (serializer == null)
 					{
+						// cannot be serialized, thus skip
 						p--;
 					}
 					else
 					{
+						// serialize first
 						byte[] bytes = serializer.serialize(page);
 						SerializedPage serializedPage = new SerializedPage(page.getPageId(), Classes.name(page.getClass()), bytes);
+
+						// and then re-add (to prevent a serialization loop,
+						// in case the page holds a reference to the session)  
 						pages.add(p, serializedPage);
 					}
 				}
diff --git a/wicket-core/src/test/java/org/apache/wicket/DefaultPageManagerProviderTest.java b/wicket-core/src/test/java/org/apache/wicket/DefaultPageManagerProviderTest.java
index ed6c4e8..9578938 100644
--- a/wicket-core/src/test/java/org/apache/wicket/DefaultPageManagerProviderTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/DefaultPageManagerProviderTest.java
@@ -17,7 +17,9 @@
 package org.apache.wicket;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 
+import org.apache.wicket.core.util.lang.PropertyResolver;
 import org.apache.wicket.page.IPageManager;
 import org.apache.wicket.pageStore.AsynchronousPageStore;
 import org.apache.wicket.pageStore.CachingPageStore;
@@ -45,6 +47,7 @@ class DefaultPageManagerProviderTest extends WicketTestCase
 		RequestPageStore request = (RequestPageStore)manager.getPageStore();
 		CachingPageStore caching = (CachingPageStore)request.getDelegate();
 		InSessionPageStore session = (InSessionPageStore)caching.getCache();
+		assertNull(PropertyResolver.getValue("serializer", session));
 		SerializingPageStore serializing = (SerializingPageStore)caching.getDelegate();
 		AsynchronousPageStore asynchronous = (AsynchronousPageStore)serializing.getDelegate();
 		DiskPageStore disk = (DiskPageStore)asynchronous.getDelegate();