In Java on FLEXIBLE google app engine, how do you disable caching of files? I don't care if it's disabled on the entire bucket with gsutil, or individual files when I save them, or when they're read. (I just don't want anything cached, as files are frequently replaced and use the same filename).
My code to store files:
private static Storage storageService;
public static void uploadStream(
String name, InputStream stream, String bucketName)
throws IOException, GeneralSecurityException {
Storage storage = StorageOptions.getDefaultInstance().getService();
Blob blob = storage.create(BlobInfo.newBuilder(bucketName, name).build(),stream);}
This code works flawlessly for uploading and replacing pdf files as intended. When the user views the pdf on the web page, if it was recently replaced, they see a cached copy. It takes an hour before the new version can be viewed on the web site.
I'm not sure if this is something where I need to edit the bucket, set no caching when saving the file in java, or set no caching when reading the file. My code for reading the file is:
public ByteArrayOutputStream downloadStream (String bucketName, String filePath)
throws Exception {
Storage storage = getService();
byte [] bytes = storage.readAllBytes(bucketName,filePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);
baos.write(bytes, 0, bytes.length);
return baos;
}
This is then returned via a web servlet.
Standard google app engine was tagged as well, as this is really a google cloud storage issue, and I'm not sure if the solution lies with gsutil or the cloud console, but note that the java code to access google cloud storage will differ between flexible and standard.