SAP Gateway always recommends implementing the $expand (therefore using the data provider expand) rather than relying on the framework $expand (generic expand) due to performance reasons.
There are strict restrictions related to the functionality of framework $expand in combination with Last-Modified and cache control:
You are not allowed to set export parameter ES_RESPONSE_CONTEXT-IS_NOT_MODIFIED to ABAP_TRUE.
The application must always return the application data in full.
The value of the if-modified-since will be suppressed (hidden) in the backend system to ensure that the application is forced to return data in full.
The different nodes of the framework $expand are allowed to return a different time stamp in export parameter ES_RESPONSE_CONTEXT-LAST_MODIFIED. In this case the following rules apply:
The youngest LAST_MODIFIED time stamp wins (will be set as response header).
If at least one LAST_MODIFIED time stamp is initial, then the LAST_MODIFIED response header is not set at all.
The different nodes are allowed to return a different MAX_AGE in export parameter ES_RESPONSE_CONTEXT-MAX_AGE. The following rules apply:
The smallest MAX_AGE wins.
If the smallest MAX_AGE is initial, then MAX_AGE is ignored altogether.
The following rule applies for export parameter ES_RESPONSE_CONTEXT-DO_NOT_CACHE_ON_CLIENT: If at least one of the nodes returns DO_NOT_CACHE_ON_CLIENT = ABAP_FALSE, then DO_NOT_CACHE_ON_CLIENT= ABAP_FALSE is valid for the entire header.