Google App Engine - Busting Serving URL Cache
Asked Answered
A

1

2

I've finally managed to get images to rotate properly on App Engine, now I'm struggling to get around images being cached and the standard cache busting techniques doesn't do anything.

So the first time I rotate the image, I get a different URL back and the image is rotated.

The second time I rotate it, I get the same URL back, only after appending =s300-c does the image rotate, the third time I rotate, I need to change that =s300-c to -s301-c in order to see the new image.

If I go back to =s300-c, I get the previous rotation of the image.

Appending ?datetimegoeshere doesn't work which leaves me to believe the caching is happening on Google's side and that it's not a browser problem.

What can I append to the image serving url in order to always get the latest version of the image?

I'm using the following code to write the rotated image:

GcsServiceFactory.createGcsService().delete(fileName);
GcsOutputChannel outputChannel = GcsServiceFactory.createGcsService().createOrReplace( fileName, GcsFileOptions.getDefaultInstance());
outputChannel.write(ByteBuffer.wrap(newImage.getImageData()));
outputChannel.close();

and this code to generate the new serving url:

String newImageUrl = imagesService.getServingUrl(ServingUrlOptions.Builder.withBlobKey(blobKey));

(rest of the source code posted here: Storing rotated / flipped images in Google App Engine)

This URL for example will give me one version of the image: http://lh5.ggpht.com/bbZLUGp07DJNdnkN-ezjO5Gu2hSTMIMWXnRkFJ8i9buEBpjMDHMOxviwuJIIS96mPA_2tYTUbokVY16oNwzrt4g0_7Q=s505-c

enter image description here

and this will return another version of the same image (even though it should be returning the same image, just with a different size): http://lh5.ggpht.com/bbZLUGp07DJNdnkN-ezjO5Gu2hSTMIMWXnRkFJ8i9buEBpjMDHMOxviwuJIIS96mPA_2tYTUbokVY16oNwzrt4g0_7Q=s504-c

enter image description here

How do I get Google App Engine to serve the latest version of the image?

Aladdin answered 10/3, 2014 at 6:12 Comment(0)
R
1

While this doesn't answer you question on cache busting it might help you solve your problem.

Try these 4 URLs

http://lh5.ggpht.com/bbZLUGp07DJNdnkN-ezjO5Gu2hSTMIMWXnRkFJ8i9buEBpjMDHMOxviwuJIIS96mPA_2tYTUbokVY16oNwzrt4g0_7Q=s0 http://lh5.ggpht.com/bbZLUGp07DJNdnkN-ezjO5Gu2hSTMIMWXnRkFJ8i9buEBpjMDHMOxviwuJIIS96mPA_2tYTUbokVY16oNwzrt4g0_7Q=s0-r90 http://lh5.ggpht.com/bbZLUGp07DJNdnkN-ezjO5Gu2hSTMIMWXnRkFJ8i9buEBpjMDHMOxviwuJIIS96mPA_2tYTUbokVY16oNwzrt4g0_7Q=s0-r180 http://lh5.ggpht.com/bbZLUGp07DJNdnkN-ezjO5Gu2hSTMIMWXnRkFJ8i9buEBpjMDHMOxviwuJIIS96mPA_2tYTUbokVY16oNwzrt4g0_7Q=s0-r270

i.e you can rotate your images on the fly without having to do it manually.

Resemblance answered 10/3, 2014 at 6:33 Comment(4)
The rotate via url param is a good solution if rotation was the only thing I'm doing; some images are flipped as well, so if a -flr and -ftb exist, then I'd rather go that route.Aladdin
lh5.ggpht.com/…Resemblance
nice, in that case I'll just need to keep track of images that are flipped / rotated. I'm still curious about solving the caching issue, so I'm going to leave it open for a bit longer.Aladdin
so the idea around the caching would be to use a different filename in GCS for your manually rotated/flipped/scaled images, so you would get a different URL for each one.Resemblance

© 2022 - 2024 — McMap. All rights reserved.