Reuse Desktops"
m |
m |
||
Line 1: | Line 1: | ||
− | {{ | + | {{ZKDevelopersReferencePageHeader}} |
__TOC__ | __TOC__ | ||
Line 9: | Line 9: | ||
First, you implement the <javadoc type="interface" /javadoc>org.zkoss.zk.ui.util.DesktopRecycle</javadoc> interface to cache and reuse the desktops which are supposedly being removed. Second, specify the class in <tt>WEB-INF/zk.xml</tt>. For example, let us assume the class you implement is called <tt>foo.MyRecycle</tt>, then add the following to <tt>zk.xml</tt> | First, you implement the <javadoc type="interface" /javadoc>org.zkoss.zk.ui.util.DesktopRecycle</javadoc> interface to cache and reuse the desktops which are supposedly being removed. Second, specify the class in <tt>WEB-INF/zk.xml</tt>. For example, let us assume the class you implement is called <tt>foo.MyRecycle</tt>, then add the following to <tt>zk.xml</tt> | ||
− | < | + | <syntax lang="xml"> |
<listener> | <listener> | ||
<listener-class>foo.MyRecycle</listener-class> | <listener-class>foo.MyRecycle</listener-class> | ||
</listener> | </listener> | ||
− | </ | + | </syntax> |
=== org.zkoss.zkmax.zk.ui.util.DesktopRecycle === | === org.zkoss.zkmax.zk.ui.util.DesktopRecycle === | ||
Line 23: | Line 23: | ||
For example, we can limit the URL to cache to <code>"/long-op/*"</code>, and re-generate the page if it has been served for more than 5 minutes. | For example, we can limit the URL to cache to <code>"/long-op/*"</code>, and re-generate the page if it has been served for more than 5 minutes. | ||
− | < | + | <syntax lang="java"> |
public class MyRecycle extends org.zkoss.zkmax.zk.ui.util.DesktopRecycle { | public class MyRecycle extends org.zkoss.zkmax.zk.ui.util.DesktopRecycle { | ||
protected boolean shallCache(Desktop desktop, String path, int cause) { | protected boolean shallCache(Desktop desktop, String path, int cause) { | ||
Line 32: | Line 32: | ||
} | } | ||
} | } | ||
− | </ | + | </syntax> |
=== Implement Your Own Desktop Recycle === | === Implement Your Own Desktop Recycle === | ||
Line 49: | Line 49: | ||
|} | |} | ||
− | {{ | + | {{ZKDevelopersReferencePageFooter}} |
Revision as of 11:10, 18 September 2010
[Since 5.0.0]
By default, a desktop is purged when the user browses to another URI or refreshes the page. Thus, the user can have the most updated information. However, if a page takes too long to generate, you can provide a plugin so-called desktop recycle.
First, you implement the DesktopRecycle interface to cache and reuse the desktops which are supposedly being removed. Second, specify the class in WEB-INF/zk.xml. For example, let us assume the class you implement is called foo.MyRecycle, then add the following to zk.xml
<syntax lang="xml"> <listener> <listener-class>foo.MyRecycle</listener-class> </listener> </syntax>
org.zkoss.zkmax.zk.ui.util.DesktopRecycle
[Enterprise Edition] [Since 5.0.0]
ZK provides a default implementation, the DesktopRecycle class, to simplify the use. You can use it directly or extends from it. By default, it caches all desktops for all URI. You can extend it to limit to certain paths by overriding the shallRecycle method, or not to use desktops older than particular time by overriding the shallReuse method.
For example, we can limit the URL to cache to "/long-op/*"
, and re-generate the page if it has been served for more than 5 minutes.
<syntax lang="java"> public class MyRecycle extends org.zkoss.zkmax.zk.ui.util.DesktopRecycle {
protected boolean shallCache(Desktop desktop, String path, int cause) { return path.startsWith("/long-op"); } protected boolean shallReuse(Desktop desktop, String path, int secElapsed) { return secElapsed >= 300; }
} </syntax>
Implement Your Own Desktop Recycle
[Since 5.0.0]
It is straightforward to implement the DesktopRecycle interface from scratch, if you prefer. The basic idea is to cache the desktop when the beforeRemove method is invoked, and to reuse the cached desktop when the beforeService method is called.
Version History
Version | Date | Content |
---|---|---|