public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
boolean varForceRefresh = false;
int refreshPeriod = 0;
int scope = PageContext.APPLICATION_SCOPE;
String forceCacheUse = null;
String key = null;
// Cache item
Long item;
// Get the admin
ServletCacheAdministrator admin = ServletCacheAdministrator.getInstance(getServletContext());
// Translate parameters
try {
String paramValue = request.getParameter("forceRefresh");
if ((paramValue != null) && (paramValue.length() > 0)) {
varForceRefresh = Boolean.valueOf(paramValue).booleanValue();
}
paramValue = request.getParameter("scope");
if ((paramValue != null) && (paramValue.length() > 0)) {
scope = getScope(paramValue);
}
paramValue = request.getParameter("refreshPeriod");
if ((paramValue != null) && (paramValue.length() > 0)) {
refreshPeriod = Integer.valueOf(paramValue).intValue();
}
forceCacheUse = request.getParameter("forcecacheuse");
key = request.getParameter("key");
} catch (Exception e) {
getServletContext().log("Error while retrieving the servlet parameters: " + e.toString());
}
// Check if all the items should be flushed
if (varForceRefresh) {
admin.flushAll();
}
try {
// Get the data from the cache
item = (Long) admin.getFromCache(scope, request, key, refreshPeriod);
} catch (NeedsRefreshException nre) {
// Check if we want to force the use of an item already in cache
if ("yes".equals(forceCacheUse)) {
admin.cancelUpdate(scope, request, key);
item = (Long) nre.getCacheContent();
} else {
item = new Long(System.currentTimeMillis());
admin.putInCache(scope, request, key, item);
}
}
// Generate the output
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("< html >");
out.println("< head >< title >OscacheServlet< /title >< /head >");
out.println("< body >");
out.println("< b >This is some cache content < /b >: " + item.toString() + "< br >");
out.println("< b >Cache key< /b >: " + admin.getCacheKey() + "< br >");
out.println("< b >Entry key< /b >: " + admin.generateEntryKey("Test_key", request, scope) + "< br >");
out.println("< /body >< /html >");
}
Process the HTTP Get request
|