216
Views
6
Comments
Exposing an image via REST Endpoint and add 'Cache-Control' | Reactive
Question

Hi all,

I am developing a way to fetch and cache images on the client side to improve page load performance. I have been successful through a workaround were I use a traditional web app's screen as a proxy to download the image and set the 'Cache-Control' header as 'public, max-age=XXXXXXXXX', in its 'Preparation'. 

Problem: with this solution the page load greatly improves over time, but on the first load, the images are being loaded synchronously. As such, I have been trying to adapt the logic to a rest API method to fetch the images asynchronously. The image content is sent in the body of a GET endpoint, and the headers are set using the same actions I used in the traditional web approach ('HTTPRequestHandler/AddHeader' actions) inside the method's 'server action'. I have achieved asynchronous load but the mentioned cache header isn't changing (cache.PNG for reference). 

My solution was inspired by the one proposed here 'https://www.outsystems.com/forge/component-overview/4528/db-image-cache' , however the cache header doesn't seem to work with this component too...

Does anyone have any idea on how I can tackle this issue?

Thanks in advance!


2020-09-10 16-14-52
Luís Rodrigues

This is the image I am referencing in the post. Sorry to whom it might concern!

cache.PNG
2025-09-16 17-12-57
João Mateus

Hi,

We have also had the issue with the REST Expose where the 'Cache Control' HTTP header is always overriden by OutSystems and is set to 'no-cache', even if we use the HTTPRequestHandler's action setHeader to change it to, for example, 'max-age=315360000' which would allow caching by the browser.

Does anyone know how to set 'Cache Control' header in OutSystems, in exposed REST actions, to something other than 'no-cache'? I believe that this would solve Luis' problem as well.

Regards,
João Mateus

2020-09-10 16-14-52
Luís Rodrigues

Yes, that would be the problem in my case too. Thank you João!  

2017-05-18 23-04-15
Carlos Faim

Hello there

Is there any news regarding this cache-control topic?

2020-03-12 15-06-24
Steven Decock

I was also trying to do the same: exposing an image through a REST API and setting Cache-Control.

No luck.  Cache-Control is always overridden.

Would also be interested if anyone can help.

2020-03-12 15-06-24
Steven Decock

An update on this issue: 

There seems to be no way to set Cache-Control for exposed REST APIs.
So, for my use case, serving images, I went for the 'old' solution using a Traditional Web Application with a screen with a Preparation that fetches the image (using a Server Action), sets the Cache-Control header using the AddHeader action from HTTPRequestHandler and ends with a Download node, returning the image with 'Save to Disk' set to 'No'.

The images are now correctly cached in the browser. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.