Skip to content

Commit

Permalink
Merge pull request #142 from ing-bank/fix/cache-head-for-all-obj
Browse files Browse the repository at this point in the history
Allow cache head requests for all objects
  • Loading branch information
arempter authored May 11, 2020
2 parents 846bc2f + ebd6a2d commit 2332697
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,14 @@ trait RequestHandlerS3Cache extends HazelcastCacheWithConf with RequestHandlerS3
val key = getKey(request)
super.fireRequestToS3(request).flatMap { response =>

if (isEligibleSize(response)) {
if (isHead(request)) {
response.entity.discardBytes()
Future.successful(HeadCacheValueObject(response.headers, response.entity.contentLengthOption, response.status))
} else {
//todo: add head request to reduce amount of get's
response.entity.toStrict(3.seconds).flatMap { r =>
r.dataBytes.runFold(ByteString.empty) { case (acc, b) => acc ++ b }
}.map(bs => GetCacheValueObject(bs))
}
if (isHead(request)) {
response.entity.discardBytes()
Future.successful(HeadCacheValueObject(response.headers, response.entity.contentLengthOption, response.status))
} else if (isEligibleSize(response)) {
//todo: add head request to reduce amount of get's
response.entity.toStrict(3.seconds).flatMap { r =>
r.dataBytes.runFold(ByteString.empty) { case (acc, b) => acc ++ b }
}.map(bs => GetCacheValueObject(bs))
} else {
response.entity.discardBytes()
Future.failed(new ObjectTooBigException())
Expand Down

0 comments on commit 2332697

Please sign in to comment.