pdfplum icon indicating copy to clipboard operation
pdfplum copied to clipboard

Configurable Cache-Control for Generated PDFs in Cloud Storage

Open mlabarrere opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe.

It would be great to have the ability to configure the Cache-Control header for the PDF files generated and uploaded by the PDFPlum extension. Currently, the extension does not offer a way to set or remove this header when uploading PDFs to Firebase Storage.

Describe the solution you'd like

Introduce a new configuration parameter, such as CACHE_CONTROL_HEADER, that allows developers to specify the desired Cache-Control behavior for the uploaded PDFs. If left empty, the default behavior (as determined by Firebase/Google Cloud Storage) would apply. Otherwise, developers could define values like no-store, no-cache, or other caching directives based on their needs.

Describe alternatives you've considered

No response

Additional context

No response

mlabarrere avatar Sep 10 '24 15:09 mlabarrere

Changing the function "storePDF" with metadata: {cacheControl: 'no-cache'}, or "no-store", is not saved within the object metadata. Hence, the cache is still up and running.

export async function storePdf({
  outputStorageBucket,
  outputStoragePrefix,
  outputFileName,
  pdf,
}: Parameters): Promise<{
  location: string | undefined;
  publicUrl: string | undefined;
}> {
  let publicUrl: string | undefined;
  const location = path.join(outputStoragePrefix ?? "", outputFileName);

  if (outputStorageBucket != null && outputStorageBucket != "") {
    const bucket = getStorage().bucket(outputStorageBucket);
    const file = bucket.file(location);

    await file.save(pdf, {
      resumable: false,
      metadata: {cacheControl: 'no-cache'}, // <- Non working Edit
      public:
        extensionParameters.SHOULD_MAKE_PDF_PUBLIC.toLowerCase() === "yes",
      
    }
    );

    publicUrl = file.publicUrl();
    return { location, publicUrl };
  } else {
    return { location: undefined, publicUrl: undefined };
  }
}

mlabarrere avatar Sep 10 '24 15:09 mlabarrere

Thanks for preparing this suggestion!

Is it possible to achieve this with separate calls to Firebase API? Wouldn't it be more aligned with the separation of concerns to let it out of the responsibilities of pdfplum?

sassanh avatar Sep 10 '24 19:09 sassanh