Disable caching in Data Provider Class, HTTP Header fields

Tags: SEGW, OData, GateWay, SAP

There are few cases, where You want to disable caching at the client side. For example the web browser of the end user will not store the server response data You collected and sent back in Your Data Provider class. After You generate Your project in SEGW transaction, the DPC_EXT class is ready to implement the method redefinitions to build responses for the client(get_entity,get_entityset etc.). Here You can use the ready to use set_header method to set HTTP Header fields in the server response. One of the header fields is the Cache-Control (read more for the exact mechanism). The following snippet demonstrates the use of set_header in context of cache management. Pragma is for backward compatibility.

METHOD set_no_cache.

DATA:
header TYPE ihttpnvp.

header-name = 'Cache-Control'.
header-value = 'no-cache, no-store'.
set_header( header ).

header-name = 'Pragma'.
header-value = 'no-cache'.
set_header( header ).

"Some more extra :)
es_response_context-do_not_cache_on_client = /iwbep/if_mgw_appl_types=>gcs_cache_on_client-do_not_cache.

ENDMETHOD.