Skip to Content
Author's profile photo Vivek Vishal

Disabling Cache for CRUD/FI OData scenarios for a UI5 Application on Internet Explorer

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 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./wp-content/uploads/2014/05/1_462384.png
  3. Copy the code from below into the redefined method !

 

Code Snippet

data: ls_header type ihttpnvp.

ls_headername = ‘Cache-Control’.

ls_headervalue = ‘no-cache, no-store’.

APPEND ls_header TO ct_headers.

ls_headername = ‘Pragma’.

ls_headervalue = ‘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.

/wp-content/uploads/2014/05/2_462385.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_headername = ‘Cache-Control’.

ls_headervalue = ‘no-cache, no-store’.

APPEND ls_header TO ct_headers.

ls_headername = ‘Pragma’.

ls_headervalue = ‘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.

/wp-content/uploads/2014/05/3_462422.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_headername = ‘Cache-Control’.

ls_headervalue = ‘no-cache, no-store’.

APPEND ls_header TO ct_headers.

ls_headername = ‘Pragma’.

ls_headervalue = ‘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 !! ๐Ÿ™‚

Assigned Tags

      20 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Exactly what I was looking for ๐Ÿ™‚ Works fine!

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Thanks Robbe. Glad it helped you !

      Author's profile photo Arno Kristel
      Arno Kristel

      This only partially worked for us. Is there anything else we can do?

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Hi Arno,

      Could you please describe your scenario in more detail and what could not work with the above solution ?

      Regards, Vivek

      Author's profile photo Stefan Heitzer
      Stefan Heitzer

      Great Blogpost!

      This was exactly what we were looking for!

      Thx a lot!!!

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Thanks Stefan !

      Author's profile photo Matt Harding
      Matt Harding

      Thanks Stefan. Saved me today and very suprised this is not automatically there inside the framework with the option to selectively change (if you do want to do caching) as this causes all sorts of grief when people use IE and you've been testing using Chrome because IE is horrible to do UI5 development/testing in.

      Cheers,

      Matt

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Thanks Matt.

      Not sure, but hopefully - It will be a part of the framework soon !

      Br, Vivek

      Author's profile photo Former Member
      Former Member

      Great. Thank you.

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Thanks !

      Author's profile photo Wolfgang Rรถckelein
      Wolfgang Rรถckelein

      Are you sure this is needed for actions besides GET? IMHO a intermediate cache or a browser will not cache POST/PUT/MERGE/DELETE requests, so the header need only to be added to GET_ENTITY and GET_ENTITYSET?

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Thanks,

      The FI READ/GET does work with theย EXEC_SERVICE_OPERATION. For all other kinds of operation that does not involve a READ, the browser generally does not cache.

      Author's profile photo Patrick Dean
      Patrick Dean

      Excellent blog - really detailed, and I like the attitude with all the smileys! Others need to learn from this example.

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Thanks Patrick !

      Author's profile photo Bilen Cekic
      Bilen Cekic

      you are the guy who saved my ass ๐Ÿ˜€ thx man

       

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Good to know that it helped you ! ๐Ÿ™‚

      Author's profile photo Ankit Garg
      Ankit Garg

      Hi Vivek ,

      Great blog you have write ,

      but can you elaborate for some parameter as you mention ย ย ls_headerโ€“name = โ€˜Pragmaโ€™. what does it mean 'Pragma' . is this program name any extension class name or method name .

      please reply

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Hi Ankit,

       

      Pragma or No Cache are identical to metadata tags that are inserted in the HTML or OData response to prevent caching. Pragma is applicable for the HTTP/1.0 implementation and Cache-Control is for the HTTP/1.1 implementations.

      The Method or the Class Names are mentioned above in the snapshots.

      Thanks.

      Author's profile photo Former Member
      Former Member

      Hi Vivek

       

      We have implemented the solution and it works fine except dumps are getting generated. Is this a known issue and can it be fixed ?

      Author's profile photo Vivek Vishal
      Vivek Vishal
      Blog Post Author

      Hi Shajitha,

       

      What is the sources of these dumps and can you provide more technical information on this ?

      i did not encounter any dump scenarios yet for this use case.

      Regards, Vivek