0

I have a batch call that calls a queuaeble that calls a future call which utilizes a visualforce page 'getContentAsPdf' function. Also in this queuable call I set a custom class value to a local partition cache.

In the getContentAsPdf, I attempt to get the cached value from the org but it returns null. I cannot seem to figure this out as the cache is supposedly available throughout the org for all requests.

1

Without seeing the design of your code, it's possible that either the results were not committed to the cache yet, the cache was invalidated for some reason, or the transaction exceeded the per transaction limits for writing to the cache.

If the cache missed because it wasn't committed yet, you'll need to probably chain your Queueable until you can confirm the data is ready. If it's simply invalidated, that means that the results of the computation were lost. Finally, if your content is potentially larger than the per-transaction limits (100kb per object), then the cache will never be able to help you.

Any way you look at it, I suspect you're using the wrong mechanism. You should use the cache to store information that is expensive to generate (usually because of CPU time), but you need to accept that the cache may miss, and your code needs to be able to perform the expensive calculation all over again. You must not assume that the cache will always contain the data when you need it.

Instead, consider storing the data into an Attachment, ContentDocument, or Document. From there, you can guarantee that your page will be able to see the content. You can delete the content after the content is generated. This also allows you to regenerate a failed process later if you need to.

  • many thanks @sfcdfox, definitely the direction i needed! – jschleicher Apr 26 '18 at 2:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.