use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class RemoteFileServlet method writeResource.
private boolean writeResource(final HttpServletRequest req, final HttpServletResponse resp, final String resourcePath) throws IOException {
IRemoteFileService rfs = BEANS.get(getConfiguredRemoteFileServiceClass());
RemoteFile spec = new RemoteFile((resourcePath == null) ? null : StringUtility.join("", m_folder, resourcePath), -1);
RemoteFile remoteFile = rfs.getRemoteFile(spec);
if (!remoteFile.exists()) {
return false;
}
HttpCacheObject obj = new HttpCacheObject(new HttpCacheKey(resourcePath), remoteFile.toBinaryResource());
if (BEANS.get(HttpCacheControl.class).checkAndSetCacheHeaders(req, resp, obj)) {
return true;
}
rfs.streamRemoteFile(remoteFile, resp.getOutputStream());
return true;
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class HtmlDocumentParser method createExternalPath.
/**
* Creates the external path of the given resource, including fingerprint and '.min' extensions. This method also
* deals with caching, since we must build a script file first, before we can calculate its fingerprint.
*/
protected String createExternalPath(String internalPath) throws IOException {
File srcFile = new File(internalPath);
String[] filenameParts = FileUtility.getFilenameParts(srcFile);
Pair<HttpCacheObject, String> scriptAndFingerprint = null;
// When caching is enabled we must calculate the fingerprint for the script file
if (m_params.isCacheEnabled()) {
scriptAndFingerprint = getScriptAndFingerprint(internalPath);
}
// append path to file
StringBuilder externalPathSb = new StringBuilder();
if (srcFile.getParent() != null) {
externalPathSb.append(srcFile.getParent()).append("/");
}
// append file name without file-extension
externalPathSb.append(getScriptFileName(filenameParts[0]));
// append fingerprint
if (scriptAndFingerprint != null) {
String fingerprint = scriptAndFingerprint.getRight();
externalPathSb.append("-").append(fingerprint);
}
// append 'min'
if (m_params.isMinify()) {
externalPathSb.append(".min");
}
// append file-extension
externalPathSb.append(".").append(getScriptFileExtension(filenameParts[1]));
String externalPath = externalPathSb.toString();
// want to access the cached file by its internal path.
if (scriptAndFingerprint != null) {
HttpCacheObject internalCacheObject = scriptAndFingerprint.getLeft();
HttpCacheKey externalCacheKey = createScriptFileLoader().createCacheKey("/" + externalPath);
HttpCacheObject externalCacheObject = new HttpCacheObject(externalCacheKey, internalCacheObject.getResource());
m_cache.put(internalCacheObject);
m_cache.put(externalCacheObject);
}
return externalPath;
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class HtmlFileLoader method createCacheKey.
@Override
public HttpCacheKey createCacheKey(String pathInfo) {
Map<String, String> attrs = new HashMap<>();
// Cache key for HTML files include locale and theme, because "<scout:message>" tags are
// locale-dependent, while CSS files (and therefore their fingerprint) are theme-dependent.
Locale locale = NlsLocale.getOrElse(null);
if (locale != null) {
attrs.put(LOCALE_KEY, locale.toString());
}
attrs.put(THEME_KEY, m_theme);
return new HttpCacheKey(pathInfo, attrs);
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class PrebuildFiles method loadResource.
protected HttpCacheObject loadResource(String file) throws IOException {
String defaultTheme = UiThemeUtility.getConfiguredTheme();
HtmlFileLoader loader = new HtmlFileLoader(defaultTheme, true, true);
HttpCacheKey cacheKey = loader.createCacheKey(file);
return loader.loadResource(cacheKey);
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class ResourceRequestHandler method resolveResourceFromCache.
protected HttpCacheObject resolveResourceFromCache(HttpServletRequest req, String pathInfoEx, IResourceLoader resourceLoader) throws IOException {
// Create cache key for resource and check if resource exists in cache
HttpCacheKey cacheKey = resourceLoader.createCacheKey(pathInfoEx);
// When caching is disabled, always load resource
if (!UrlHints.isCacheHint(req)) {
LOG.debug("Requested resource with cacheKey={}. Caching is disabled by URL hint", cacheKey);
return resourceLoader.loadResource(cacheKey);
}
IHttpResourceCache resourceCache = resourceLoader.getCache(cacheKey);
if (resourceCache == null) {
LOG.debug("Loader for resource with cacheKey={} does not support caching.", cacheKey);
return resourceLoader.loadResource(cacheKey);
}
String cacheResultMsg;
HttpCacheObject resource = resourceCache.get(cacheKey);
if (resource == null) {
// Cache miss: resource not found in cache --> load it
resource = resourceLoader.loadResource(cacheKey);
if (resource == null) {
cacheResultMsg = "Resource is not cached (cache miss), could not load resource (not added to the cache)";
} else {
resourceCache.put(resource);
cacheResultMsg = "Resource is not cached (cache miss), resource loaded and added to the cache";
}
} else {
// Cache hit
cacheResultMsg = "Resource found in cache (cache hit), using cached resource";
}
LOG.debug("Requested resource with cacheKey={}. {}", cacheKey, cacheResultMsg);
return resource;
}
Aggregations