diff --git a/grails-app/resourceMappers/org/grails/plugin/cachedresources/HashAndCacheResourceMapper.groovy b/grails-app/resourceMappers/org/grails/plugin/cachedresources/HashAndCacheResourceMapper.groovy index c576604..b62606b 100644 --- a/grails-app/resourceMappers/org/grails/plugin/cachedresources/HashAndCacheResourceMapper.groovy +++ b/grails-app/resourceMappers/org/grails/plugin/cachedresources/HashAndCacheResourceMapper.groovy @@ -28,7 +28,12 @@ class HashAndCacheResourceMapper { if (log.debugEnabled) { log.debug "Setting caching headers on ${req.requestURI}" } - cacheHeadersService.cache resp, [neverExpires: true, shared: true] + + if (isCachedOnClient(req)) { + resp.sendError(304) // Not modified + } else { + cacheHeadersService.cache resp, [neverExpires: true, shared: true] + } } } @@ -51,6 +56,23 @@ class HashAndCacheResourceMapper { param } } + + boolean isCachedOnClient(request) { + def modifiedDate = -1 + + try { + modifiedDate = request.getDateHeader('If-Modified-Since') + } catch (IllegalArgumentException iae) { + log.error ("Couldn't parse If-Modified-Since header", iae) + } + + if (modifiedDate != -1) { + // Resource is static, if the If-Modified-Since header is set the resource is cached + return true + } + + false + } boolean getShortenLinks() { resourceService.getConfigParamOrDefault('shorten', true)