Quantcast
Channel: SCN : Blog List - SAP Gateway
Viewing all articles
Browse latest Browse all 245

Disabling Cache for CRUD/FI OData scenarios for a UI5 Application using IE

$
0
0

This Blog attempts to make its audience understand the way to disable the cache content for UI5 Applications using SAP Netweaver Gateway/OData. It should be noted that there are mechanisms to disable the cache in a UI5 development environment but the blog focusses on disabling them using SAP Netweaver Gateway Implementation.

 

Understanding the Scenario/I'm Curious

 

Q: What is the need to disable the CACHE in a UI5 Application that consumes OData Services ?

A: While performing a specific change/functionality in a UI5 application, it is desired that the Application loads fresh data from the backend and does not display stale/unchanged data.

 

Q: When does this happen ?

A: Specifically, When an OData service is called to perform an UPDATE operation, A Read is not enforced to fetch the updated DATA.

 

Q: So Why use GATEWAY/OData to disable cache on a service layer, Why not UI5 environment on an application layer ?

A: UI5 applications are browser specific applications. For some of the browsers: IE, Firefox - The browser engine does not force a cache RE-READ and has its limitations when trying to READ the data after an update is performed.

 

Q: Is this a restriction on only CRUD Services ?

A: This behaviour is exhibited for CRUD and Function Import/Non CRUD Operations as well.

 

Q: Is this a common development to adapt for for all the browsers ?

A: IE specifically, Firefox and Chrome are scenario centric.

 

 

Feeling contented.... Read Further ...

 

~~ How do I do it ?

  • Ok, Let's get down to some Business. What OData scenario am I looking at ?

          How about a CRUD Operation : Let's say an Update !

       

  1. Navigate to your DPC Ext Implementation and locate the CORE_SRV_RUNTIME~READ_ENTITYSET Implementation.
  2. Redefine the method by clicking on the icon as shown in the snapshot.1.png
  3. Copy the code from below into the redefined method !

  

Code Snippet

 

data: ls_header type ihttpnvp.

 

ls_header-name = 'Cache-Control'.

ls_header-value = 'no-cache, no-store'.

APPEND ls_header TO ct_headers.

ls_header-name = 'Pragma'.

ls_header-value = 'no-cache'.

APPEND ls_header TO ct_headers.

 

CALL METHOD SUPER->/IWBEP/IF_MGW_CORE_SRV_RUNTIME~READ_ENTITYSET

    EXPORTING

      iv_entity_name                = iv_entity_name

      iv_source_name              = iv_source_name

      is_paging                          = is_paging

      it_order                               = it_order

      it_filter_select_options  = it_filter_select_options

      is_request_details           = is_request_details

    CHANGING

      ct_headers                         = ct_headers

      cr_entityset                       = cr_entityset     .

 

Looks Simple ? Does it solve my problem.......?

 

Wait !! This is a READ ENTITYSET Implementation.

What if the Data that I'm trying to update is expected from an Entity and not an Entity Set ??     .

As every problem has a solution so does this one ! 

 

4. Navigate to your DPC Ext implementation and Locate the CORE_SRV_RUNTIME~READ_ENTITY Implementation.

2.png

 

5. Redefine the method by clicking on the icon in the first snapshot as shown above.

 

6. Next, copy the code from below into the redefined method !

 

Code Snippet

 

data: ls_header type ihttpnvp.

 

ls_header-name = 'Cache-Control'.

ls_header-value = 'no-cache, no-store'.

APPEND ls_header TO ct_headers.

ls_header-name = 'Pragma'.

ls_header-value = 'no-cache'.

APPEND ls_header TO ct_headers.

 

CALL METHOD SUPER->/IWBEP/IF_MGW_CORE_SRV_RUNTIME~READ_ENTITY

   EXPORTING

     iv_entity_name       = iv_entity_name

     iv_source_name     = iv_source_name

     is_request_details  = is_request_details

   CHANGING

     ct_headers            = ct_headers

     cr_entity               = cr_entity.


Hmmm.....What If I'm calling a Function Import Service to update the Data ? Does the above Read Entity/Read Entity Set implementation takes care of the behaviour as well ?

Not Really. We need to implement something more now !

 

7. Navigate to your DPC Ext implementation and Locate the CORE_SRV_RUNTIME~EXEC_SERVICE_OPERATION Implementation.

3.png

 

8. Redefine the method by clicking on the icon in the first snapshot as shown above..

 

9. Copy the code from below into the redefined method !

 

Code Snippet

 

data: ls_header type ihttpnvp.

 

ls_header-name = 'Cache-Control'.

ls_header-value = 'no-cache, no-store'.

APPEND ls_header TO ct_headers.

ls_header-name = 'Pragma'.

ls_header-value = 'no-cache'.

APPEND ls_header TO ct_headers.

 

CALL METHOD SUPER->/IWBEP/IF_MGW_CORE_SRV_RUNTIME~EXEC_SERVICE_OPERATION

   EXPORTING

     iv_action_name     = iv_action_name

     iv_return_type     = iv_return_type

     iv_multiplicity    = iv_multiplicity

     is_request_details = is_request_details

   CHANGING

     ct_headers         = ct_headers

     cr_data            = cr_data.

 

10. Lastly, Remember to activate all the implementations.

 

That's it. That's all you need to implement.

You can access your UI5 OData application on Internet Explorer without pondering over - Why the Data was not getting updated ? !!!

 

Thank you for spending time on this space. Glad if it helped you !!


Viewing all articles
Browse latest Browse all 245

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>