Commits

Anonymous committed b12c616

New option: Don't cache requests if session id is contained in URL
Issue number: CACHE-120
Submitted by: Lars Torunski

Comments (0)

Files changed (1)

src/core/java/com/opensymphony/oscache/web/filter/CacheFilter.java

     public static final int FRAGMENT_AUTODETECT = -1;
     public static final int FRAGMENT_NO = 0;
     public static final int FRAGMENT_YES = 1;
+    
+    // No cache options
+    public static final int NOCACHE_OFF = 0;
+    public static final int NOCACHE_SESSION_ID_IN_URL = 1;
 
     // request attribute to avoid reentrance
     private final static String REQUEST_FILTERED = "__oscache_filtered";
     private int cacheScope = PageContext.APPLICATION_SCOPE; // filter scope - default is APPLICATION
     private int fragment = FRAGMENT_AUTODETECT; // defines if this filter handles fragments of a page - default is auto detect
     private int time = 60 * 60; // time before cache should be refreshed - default one hour (in seconds)
+    private int nocache = NOCACHE_OFF; // defines special no cache option for the requests - default is off
 
     /**
      * Filter clean-up
      * <li><b>fragment</b> - defines if this filter handles fragments of a page. Acceptable values
      * are <code>-1</code> (auto detect), <code>0</code> (false) and <code>1</code> (true).
      * The default value is auto detect.</li>
+     * <li><b>nocache</b> - defines which objects shouldn't be cached. Acceptable values
+     * are <code>off</code> (default) and <code>sessionIdInURL</code> if the session id is
+     * contained in the URL.
      *
      * @param filterConfig The filter configuration
      */
         } catch (Exception e) {
             log.info("Could not get init parameter 'fragment', defaulting to 'auto detect'.");
         }
+        
+        try {
+            String nocacheString = config.getInitParameter("nocache");
+            
+            if (nocacheString.equals("off")) {
+                nocache = NOCACHE_OFF;
+            } else if (nocacheString.equalsIgnoreCase("sessionIdInURL")) {
+                nocache = NOCACHE_SESSION_ID_IN_URL;
+            } 
+        } catch (Exception e) {
+            log.info("Could not get init parameter 'nocache', defaulting to 'off'.");
+        }
+
     }
 
     /**
      * @return Returns a boolean indicating if the request can be cached or not.
      */
     protected boolean isCacheable(ServletRequest request) {
-        // TODO implement CACHE-120, CACHE-137 and CACHE-141 here
+        // TODO implement CACHE-137 and CACHE-141 here
         boolean cachable = request instanceof HttpServletRequest;
 
+        if (cachable) {
+            HttpServletRequest requestHttp = (HttpServletRequest) request;
+            if (nocache == NOCACHE_SESSION_ID_IN_URL) { // don't cache requests if session id is in URL
+                cachable = !requestHttp.isRequestedSessionIdFromURL();
+            }
+        }
+
         if (log.isDebugEnabled()) {
             log.debug("<cache>: the request " + ((cachable) ? "is" : "is not") + " cachable.");
         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.