Revision: 647
          http://stripes.svn.sourceforge.net/stripes/?rev=647&view=rev
Author:   bengunter
Date:     2007-12-05 21:38:35 -0800 (Wed, 05 Dec 2007)

Log Message:
-----------
STS-449: Add annotation to control client-side caching. Default expires value 
is now HttpCache.DEFAULT_EXPIRES (Integer.MIN_VALUE). Fixed some broken logic 
that caused document to expire immediately by default. Also fixed some math in 
the comments.

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/action/HttpCache.java
    
trunk/stripes/src/net/sourceforge/stripes/controller/HttpCacheInterceptor.java

Modified: trunk/stripes/src/net/sourceforge/stripes/action/HttpCache.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/action/HttpCache.java     
2007-12-06 05:13:14 UTC (rev 646)
+++ trunk/stripes/src/net/sourceforge/stripes/action/HttpCache.java     
2007-12-06 05:38:35 UTC (rev 647)
@@ -38,7 +38,7 @@
  * <li>[EMAIL PROTECTED] @HttpCache(allow=true)} - Same as above.</li>
  * <li>[EMAIL PROTECTED] @HttpCache(allow=false)} - Set headers to disable 
caching and immediately expire the
  * document.</li>
- * <li>[EMAIL PROTECTED] @HttpCache(expires=3600)} - Caching is allowed. The 
document expires in 10 minutes.</li>
+ * <li>[EMAIL PROTECTED] @HttpCache(expires=600)} - Caching is allowed. The 
document expires in 10 minutes.</li>
  * </ul>
  * </p>
  * 
@@ -50,6 +50,9 @@
 @Inherited
 @Documented
 public @interface HttpCache {
+    /** Default value for [EMAIL PROTECTED] #expires()}. */
+    public static final int DEFAULT_EXPIRES = Integer.MIN_VALUE;
+
     /** Indicates whether the response should be cached by the client. */
     boolean allow() default true;
 
@@ -58,5 +61,5 @@
      * false, then this value is ignored and zero is used. If [EMAIL 
PROTECTED] #allow()} is true and this
      * value is less than zero, then no Expires header is sent.
      */
-    int expires() default 0;
+    int expires() default DEFAULT_EXPIRES;
 }

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/HttpCacheInterceptor.java
===================================================================
--- 
trunk/stripes/src/net/sourceforge/stripes/controller/HttpCacheInterceptor.java  
    2007-12-06 05:13:14 UTC (rev 646)
+++ 
trunk/stripes/src/net/sourceforge/stripes/controller/HttpCacheInterceptor.java  
    2007-12-06 05:38:35 UTC (rev 647)
@@ -99,7 +99,7 @@
                 HttpServletResponse response = context.getResponse();
                 if (annotation.allow()) {
                     long expires = annotation.expires();
-                    if (expires >= 0) {
+                    if (expires != HttpCache.DEFAULT_EXPIRES) {
                         logger.debug("Response expires in ", expires, " 
seconds");
                         expires = expires * 1000 + System.currentTimeMillis();
                         response.setDateHeader("Expires", expires);
@@ -152,11 +152,12 @@
         if (annotation != null) {
             logger.debug("Found ", HttpCache.class.getSimpleName(), " for ", 
beanClass.getName(),
                     ".", method.getName(), "()");
-            if (annotation.allow() && annotation.expires() < 0) {
+            int expires = annotation.expires();
+            if (annotation.allow() && expires != HttpCache.DEFAULT_EXPIRES && 
expires < 0) {
                 logger.warn(HttpCache.class.getSimpleName(), " for ", 
beanClass.getName(), ".",
                         method.getName(), "() allows caching but expires in 
the past");
             }
-            else if (!annotation.allow() && annotation.expires() != 0) {
+            else if (!annotation.allow() && expires != 
HttpCache.DEFAULT_EXPIRES) {
                 logger.warn(HttpCache.class.getSimpleName(), " for ", 
beanClass.getName(), ".",
                         method.getName(), "() disables caching but explicitly 
sets expires");
             }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to