Skip to content

Commit

Permalink
Merge 9ad50ea into 5f0b987
Browse files Browse the repository at this point in the history
  • Loading branch information
niekraaijmakers committed Apr 7, 2019
2 parents 5f0b987 + 9ad50ea commit c0f6764
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public class ResourceTypeHttpCacheConfigExtension implements HttpCacheConfigExte
public static final String PROP_CHECK_CONTENT_RESOURCE_TYPE = "httpcache.config.extension.resource-types.page-content";
private boolean checkContentResourceType;


@Property(label = "Check resourceSuperType",
description = "Should the resourceType check check super Types?",
boolValue = false)
public static final String PROP_CHECK_RESOURCE_SUPER_TYPE = "httpcache.config.extension.resource-types.superType";
private boolean checkResourceSuperType;

@Property(label = "Config Name",
description = "")
private static final String PROP_CONFIG_NAME = "config.name";
Expand Down Expand Up @@ -115,14 +122,28 @@ public boolean accepts(SlingHttpServletRequest request, HttpCacheConfig cacheCon
}
log.debug("ResourceHttpCacheConfigExtension checking for resource type matches");
// Match resource types.
for (Pattern pattern : resourceTypePatterns) {
Matcher m = pattern.matcher(candidateResource.getResourceType());
if (checkResourceType(candidateResource)) return true;

return false;
}

if (m.matches()) {
if (log.isTraceEnabled()) {
log.trace("ResourceHttpCacheConfigExtension accepts request [ {} ]", candidateResource);
private boolean checkResourceType(Resource candidateResource) {
if(checkResourceSuperType){
for (Pattern pattern : resourceTypePatterns) {
if( candidateResource.getResourceResolver().isResourceType(candidateResource, pattern.pattern())){
return true;
}
}
}else{
for (Pattern pattern : resourceTypePatterns) {
Matcher m = pattern.matcher(candidateResource.getResourceType());

if (m.matches()) {
if (log.isTraceEnabled()) {
log.trace("ResourceHttpCacheConfigExtension accepts request [ {} ]", candidateResource);
}
return true;
}
return true;
}
}

Expand Down Expand Up @@ -160,7 +181,7 @@ public boolean doesKeyMatchConfig(CacheKey key, HttpCacheConfig cacheConfig) thr
protected void activate(Map<String, Object> configs) {
resourceTypePatterns = ParameterUtil.toPatterns(PropertiesUtil.toStringArray(configs.get(PROP_RESOURCE_TYPES), new String[]{}));
pathPatterns = ParameterUtil.toPatterns(PropertiesUtil.toStringArray(configs.get(PROP_PATHS), new String[]{}));
checkContentResourceType = PropertiesUtil.toBoolean(configs.get(PROP_CHECK_CONTENT_RESOURCE_TYPE), false);
checkResourceSuperType = PropertiesUtil.toBoolean(configs.get(PROP_CHECK_CONTENT_RESOURCE_TYPE), false);

log.info("ResourceHttpCacheConfigExtension activated/modified.");
}
Expand Down

0 comments on commit c0f6764

Please sign in to comment.