SAP Gateway Cache – “Soft State”

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 Architecture

 

SAP Gateway Cache Implementation Steps

The list of steps to do in your Gateway Service to enable the HTTP Caching ( Soft-Cache)

  1. Redefine the DEFINE method of the model provider extension call
  2. Create an instance attribute MV_IS_SOFTSTATE for the DPC_EXT class that stores? the status whether soft state is activated
  3. Redefine the method /IWBEP/IF_MGW_SOST_SRV_RUNTIME~OPERATION_START to set this variable

Implementation in the Model Provider Class

  1. Redefine the DEFINE Method of the Model Provider Class. ( in _EXT Classn so it is not regenerated each time, the service is updated )

Implementation in the Data?Provider Class

1. ?Add new?attribute with the following settings

  • Attribute:?MV_IS_SOFTSTATE
  • Level:?Instance Attribute
  • Visibility:?Private
  • Typing:?Type
  • 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.

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

  • Attribute:?GV_COUNT
  • Level:?Static Attribute
  • Visibility:?Protected
  • Typing:?Type
  • 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.

SAP Gateway Cache - Soft State KO

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.

SAP Gateway Cache - Soft State OKIf 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

 

*Reference:?How to use Soft-State support for OData services