Reuse Desktops"

From Documentation
m
m (remove empty version history (via JWB))
 
(8 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
__TOC__
 
__TOC__
  
[Since 5.0.0]
+
{{versionSince|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''.
 
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 <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 <code>WEB-INF/zk.xml</code>. For example, let us assume the class you implement is called <code>foo.MyRecycle</code>, then add the following to <code>zk.xml</code>
  
<syntax lang="xml">
+
<syntaxhighlight line lang="xml">
 
<listener>
 
<listener>
 
<listener-class>foo.MyRecycle</listener-class>
 
<listener-class>foo.MyRecycle</listener-class>
 
</listener>
 
</listener>
</syntax>
+
</syntaxhighlight>
  
=== org.zkoss.zkmax.zk.ui.util.DesktopRecycle ===
+
=== org.zkoss.zkmax.ui.util.DesktopRecycle ===
[Enterprise Edition]
+
{{ZK EE}}
[Since 5.0.0]
+
{{versionSince|5.0.0}}
  
ZK provides a default implementation, the <javadoc>org.zkoss.zkmax.ui.util.DesktopRecycle</javadoc> 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 <tt>shallRecycle</tt> method, or not to use desktops older than particular time by overriding the <tt>shallReuse</tt> method.
+
ZK provides a default implementation, the <javadoc>org.zkoss.zkmax.ui.util.DesktopRecycle</javadoc> class, to simplify the use. You can use it directly or extend from it. By default, it caches all desktops for all URIs. You can extend it to limit to certain paths by overriding the <code>shallRecycle</code> method, or not to use desktops older than a particular time by overriding the <code>shallReuse</code> method.
  
 
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">
+
<syntaxhighlight line lang="java">
public class MyRecycle extends org.zkoss.zkmax.zk.ui.util.DesktopRecycle {
+
public class MyRecycle extends org.zkoss.zkmax.ui.util.DesktopRecycle {
 
   protected boolean shallCache(Desktop desktop, String path, int cause) {
 
   protected boolean shallCache(Desktop desktop, String path, int cause) {
 
     return path.startsWith("/long-op");
 
     return path.startsWith("/long-op");
Line 32: Line 32:
 
   }
 
   }
 
}
 
}
</syntax>
+
</syntaxhighlight>
  
 
=== Implement Your Own Desktop Recycle ===
 
=== Implement Your Own Desktop Recycle ===
[Since 5.0.0]
+
{{versionSince|5.0.0}}
  
It is straightforward to implement the <javadoc type="interface" >org.zkoss.zk.ui.util.DesktopRecycle</javadoc> interface from scratch, if you prefer. The basic idea is to cache the desktop when the <tt>beforeRemove</tt> method is invoked, and to reuse the cached desktop when the <tt>beforeService</tt> method is called.
+
It is straightforward to implement the <javadoc type="interface" >org.zkoss.zk.ui.util.DesktopRecycle</javadoc> interface from scratch, if you prefer. The basic idea is to cache the desktop when the <code>beforeRemove</code> method is invoked, and to reuse the cached desktop when the <code>beforeService</code> method is called.
  
=Version History=
 
  
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 10:23, 5 February 2024

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

1 <listener>
2 	<listener-class>foo.MyRecycle</listener-class>
3 </listener>

org.zkoss.zkmax.ui.util.DesktopRecycle

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png

Since 5.0.0

ZK provides a default implementation, the DesktopRecycle class, to simplify the use. You can use it directly or extend from it. By default, it caches all desktops for all URIs. You can extend it to limit to certain paths by overriding the shallRecycle method, or not to use desktops older than a 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.

1 public class MyRecycle extends org.zkoss.zkmax.ui.util.DesktopRecycle {
2   protected boolean shallCache(Desktop desktop, String path, int cause) {
3     return path.startsWith("/long-op");
4   }
5   protected boolean shallReuse(Desktop desktop, String path, int secElapsed) {
6     return secElapsed >= 300;
7   }
8 }

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.




Last Update : 2024/02/05

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.