Skip to content

Commit

Permalink
enable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
vladisavvv committed Nov 27, 2024
1 parent 155decc commit ac35f13
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ public ResourceStream getResourceStream(ResourceDescriptor resource, EtagHeader
String contentType = metadata.getContentMetadata().getContentType();
Long length = metadata.getContentMetadata().getContentLength();

if (length <= maxSize) {
result = blobToResult(blob, metadata);
redisPut(key, result);
return ResourceStream.fromResult(result, etagHeader);
}

etagHeader.validate(etag);
return new ResourceStream(payload.openStream(), etag, contentType, length);
}
Expand Down Expand Up @@ -385,9 +391,17 @@ private ResourceItemMetadata putResource(
String newEtag = EtagBuilder.generateEtag(body);
Result result = new Result(body, newEtag, createdAt, updatedAt, contentType,
descriptor.getType().requireCompression(), (long) body.length, descriptor.getType().name(), false);
flushToBlobStore(redisKey);
String blobKey = blobKey(descriptor);
blobPut(blobKey, result);
if (body.length <= maxSize) {
redisPut(redisKey, result);
if (metadata == null) {
String blobKey = blobKey(descriptor);
blobPut(blobKey, result.toStub()); // create an empty object for listing
}
} else {
flushToBlobStore(redisKey);
String blobKey = blobKey(descriptor);
blobPut(blobKey, result);
}

ResourceEvent.Action action = metadata == null
? ResourceEvent.Action.CREATE
Expand Down

0 comments on commit ac35f13

Please sign in to comment.