I am currently developing a synchronization service that fetches all user profile pictures from an exchange server. In order to track changes, i have decided to MD5 encode the response body and persist it with the entity in the database in order to compare it further down the path and see if the picture has changed. While the actual picture itself is saved on the disk.
The pictures are 504x504 pixels large and thus, weight around ~27 kb. And since i am taking the hash value of the bytecode, even if the picture matches, i still have to download the 27kb array which leads to almost no speed improvement (aside from the fact that i dont have to replace it on the disk). Multiply that by a huge amount of users and the job takes 20minutes even if all the pictures match.
Is there a way to optimize the synchronization so i do not download the response body if a picture is the same? Here is some code the help you understand better:
entity = restTemplate.getForEntity(
Constant.EXCHANGE_URL_PREFIX + emailAddress + Constant.EXCHANGE_URL_SUFFIX, byte[].class);
This is how i call the get request.
if (entity.hasBody()) {
String hexHash = Hex.encodeHexString(MessageDigest.getInstance("MD5").digest(bytes));
if (!listofHashes.contains(hexHash)) {
picture.remove();
} else picture.save();
}
To sum it up: is there a way of detecting webpage changes using restTemplate that does not download the entire page? Thank you in advance.
Edit: Additional research into the ETag header as well as the @Cacheable annotation did not prove succesful.