- java.lang.Object
-
- com.aoapps.servlet.ServletContextCache
-
public final class ServletContextCache extends Object
ServletContext methods can be somewhat slow, this offers a cache that refreshes the recently used values in the background. Importantly, it caches misses as well.- Author:
- AO Industries, Inc.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classServletContextCache.Initializer
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static ServletContextCachegetCache(ServletContext servletContext)Deprecated.Please usegetInstance(javax.servlet.ServletContext).static ServletContextCachegetInstance(ServletContext servletContext)Gets or creates the cache for the provided servlet context.longgetLastModified(String path)Gets a modified time from either a file or URL.static longgetLastModified(ServletContext servletContext, String path)StringgetRealPath(String path)static StringgetRealPath(ServletContext servletContext, String path)URLgetResource(String path)Gets the possibly cached URL.static URLgetResource(ServletContext servletContext, String path)
-
-
-
Method Detail
-
getInstance
public static ServletContextCache getInstance(ServletContext servletContext)
Gets or creates the cache for the provided servlet context.
-
getCache
@Deprecated public static ServletContextCache getCache(ServletContext servletContext)
Deprecated.Please usegetInstance(javax.servlet.ServletContext).
-
getResource
public URL getResource(String path) throws MalformedURLException
Gets the possibly cached URL. This URL is not copied and caller should not fiddle with its state. Thank you Java for this not being immutable.- Throws:
MalformedURLException- See Also:
ServletContext.getResource(java.lang.String)
-
getResource
public static URL getResource(ServletContext servletContext, String path) throws MalformedURLException
- Throws:
MalformedURLException- See Also:
getResource(java.lang.String)
-
getRealPath
public static String getRealPath(ServletContext servletContext, String path)
- See Also:
getRealPath(java.lang.String)
-
getLastModified
public long getLastModified(String path)
Gets a modified time from either a file or URL.- Returns:
- The modified time or
0Lwhen not known - See Also:
getRealPath(java.lang.String),File.lastModified(),getResource(java.lang.String),URLConnection.getLastModified()
-
getLastModified
public static long getLastModified(ServletContext servletContext, String path)
- See Also:
getLastModified(java.lang.String)
-
-