SAP Gateway Cache is new option to handle access to big amount of data. Because RFC call can take a long time to execute the different Operation CRUD ( Create, Read, Update and Delete). This new Caching functionality so-called Soft-State?enable caching the RFC returns and avoid a new call. A typical use for SAP Gateway Cache is Pricing calculation.?
SAP Gateway Cache – “Soft State”
The so-called ?soft state? mode enables the SAP NetWeaver Gateway runtime to process several requests in one ABAP application server session, similar to stateful behavior. The only difference is the behavior of the application server after the session times out: Instead of breaking the request processing with a time-out exception the server creates a new session and processes the request as usual. For the consumer the change of the application server sessions is transparent and no data is lost on the client session.
The session that is held by the ICF framework results in session held in the backend system via RFC where the data provider class can cache data in member variables. The Data Provider Cache is highlighted in green in the following figure.
Architecture of SAP Gateway Caching
The following diagram explains how the Soft Caching works
SAP Gateway Cache Implementation Steps
The list of steps to do in your Gateway Service to enable the HTTP Caching ( Soft-Cache)
- Redefine the DEFINE method of the model provider extension call
- Create an instance attribute MV_IS_SOFTSTATE for the DPC_EXT class that stores? the status whether soft state is activated
- Redefine the method /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_START to set this variable
Implementation in the Model Provider Class
- Redefine the DEFINE Method of the Model Provider Class. ( in _EXT Classn so it is not regenerated each time, the service is updated )
model->set_soft_state_enabled( abap_true ).
Implementation in the Data?Provider Class
1. ?Add new?attribute with the following settings
- Level:?Instance Attribute
- Associated Type:?ABAP_BOOL
- Description:TRUE if we are running in softstate mode
2. Refine the Method?/IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_START
- Set the previously added attribute?MV_IS_SOFTSTATE to abap_true to activate the Soft-Cache.
mv_is_softstate = abap_true.
3. Refine the Method?/IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_END
Without adding any code. Actually, once the OPERATION_START method is defined, you have to define the OPERATION_END, else you will get an exeption.
Note, that /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_END?is where you can perform?action for example to handle persistance state of exchanged data.
4. Define a new Static Attribute GV_COUNT
- Level:?Static Attribute
- Associated Type:?I
- Description:?Store counter
5. Activate all the Changes
Implementation on Gateway Hub
1. Launch the SAP Gateway Maintenance Service Transaction /IWFND/MAINT_SERVICE and confirm the Hub redirection warning if you got one
2. Click on Soft-State button.?You will probably get an error ( just confirm the error popup).
The service is shown as not Soft-State enable.
3. Load the metadata in order to retrieve the new information.
You will see that the service is Soft-State enable but the Soft-State is not active yet.
If the Soft-state stills not yet actived, try empty the Gateway cache:
- in BackEnd,?/IWBEP/CACHE_CLEANUP?and check?Cleanup Cache for all Models.
- in Gateway hub, /IWFND/CACHE_CLEANUP?with?box Cleanup Cache for all Models checked
4. Change the session time out
In the ICC node, go to?ICF Node –> Configure (SICF).
Navigate to your service and set a Session Timeout a value > than 0.
5. Now, you can active the Soft-State by clicking on the button on /IWFND/MAIN_SERVICE
Confirm the warning and your service is Soft-State Active !!!
Example of SAP Gateway Cache
In order to implement the SAP Gateway Cache, you have to modify the DPC Method XXX_GET_ENTITYSET where you retrieve data.
Here a sample example, for SAP Gateway cache of PRODUCT
DATA lv_count_requested TYPE abap_bool.
" Check if Count $Count is set to the Odata Call
lv_count_requested = io_tech_request_context->has_count( ).
IF lv_count_requested EQ abap_true.
" Check if SAP Gateway Cache or Soft-State is active
IF mv_is_softstate = abap_false.
" if no, Calculate a new count
SELECT COUNT( * ) INTO gv_count FROM SNWD_PD.
" If count is initial, calculate it
IF gv_count is INITIAL.
SELECT COUNT( * ) INTO gv_count FROM SNWD_PD.
" Else, increment the count
gv_count = gv_count + 1.
" Return The counter
es_response_context-count = gv_count.
" Else, retrieve the whole data
CALL FUNCTION 'BAPI_EPM_PRODUCT_GET_LIST'
HEADERDATA = et_entityset.
*Reference:?How to use Soft-State support for OData services