Google App Engine - Busting Serving URL Cache

让人想犯罪 __ 提交于 2019-12-11 03:57:53

问题


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

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

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


回答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.



来源:https://stackoverflow.com/questions/22293229/google-app-engine-busting-serving-url-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!