Skip to content

Commit

Permalink
fix: Fix Branding Rest Brwoser Caching behavior - MEED-7164 - Meeds-i…
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker committed Jul 3, 2024
1 parent 35ac7bf commit 19d823c
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,26 @@ public BrandingRestResourcesV1(BrandingService brandingService) {
@ApiResponse(responseCode = "304", description = "Resource not modified"),
@ApiResponse(responseCode = "500", description = "Server error when retrieving branding information")
})
public Response getBrandingInformation(@Context
Request request) {
public Response getBrandingInformation(
@Context
Request request,
@Parameter(description = "Whether force refresh information from database or not")
@QueryParam("forceRefresh")
String forceRefresh) {
try {
boolean refresh = StringUtils.equals("true", forceRefresh);
long lastUpdated = brandingService.getLastUpdatedTime();
EntityTag eTag = new EntityTag(String.valueOf(lastUpdated));
EntityTag eTag = refresh ? null : new EntityTag(String.valueOf(lastUpdated));

//
Response.ResponseBuilder builder = request.evaluatePreconditions(eTag);
if (builder == null) {
Branding brandingInformation = brandingService.getBrandingInformation(false);
Branding brandingInformation = brandingService.getBrandingInformation(refresh);
builder = Response.ok(brandingInformation);
CacheControl cc = new CacheControl();
cc.setMustRevalidate(true);
builder.tag(eTag);
builder.lastModified(new Date(lastUpdated));
builder.expires(new Date(System.currentTimeMillis() + CACHE_IN_MILLI_SECONDS));
builder.cacheControl(cc);
}
return builder.build();
Expand Down

0 comments on commit 19d823c

Please sign in to comment.