Is there a way to cache OData HTTP response?

Posted by: james.ingham on 9 December 2021, 8:18 pm EST

  • Posted 9 December 2021, 8:18 pm EST

    Dear support,

    I am looking at the OASIS OData of Wijmo and have built the server APIs guided by:

    https://www.grapecity.com/wijmo/docs/Topics/Grid/DataBinding/Binding-to-OData

    One problem we are facing is that every time user doing search, filtering or paging then a separate HTTP request will be sent which seems to be out of the coder’s control. Our project is using Angular + wijmo and we have our own caching mechanism by utilizing Angular’s http interceptor and localStorage, however we don’t know how to alter Wijmo odata’s internal behavior to cache Http response if necessary.

    Is it possible to cache this data?

  • Posted 10 December 2021, 6:10 am EST

    Hello,

    As per our understanding, you want to perform client-side caching if so then you can do so by overriding the ODataCollectionView’s internal method called _getData. You can override this method and write your caching logic to send server requests on-demand.

    If you still face any issues then you can let us know.

    Regards

  • Posted 10 December 2021, 6:40 am EST

    Yes, what we want is client-side caching. Since _getData is an internal method, I couldn’t find documentation on it. It looks like the first parameter of _getData() is the API path, and the second one is a callback function with XMLHttpRequest as the input data. Do we have to build a fake XMLHttpRequest with the client-side cached data, and then pass it to the callback?

  • Posted 14 December 2021, 1:22 am EST

    Hello,

    Yes, your observation is correct. You would be required to build a fake XMLHttpRequest with the client-side cached data to pass it to the callback.

    Also, we are working on a sample to demonstrate the same, we will provide you an update at the earliest.

    Regards

  • Posted 4 January 2022, 12:58 am EST

    Hello,

    We have prepared a sample demonstrating a generic way to cache the data by the handle underlining XMLHttpRequest. In the case of wijmo, it uses the underlying XMLHttpRequest object to make http calls. You may override wijmo’s httpRequest method to add the required logic. You can update the caching mechanism as per your requirement. Please refer to the sample link below for the same:

    https://codesandbox.io/s/elated-pasteur-ezxpn?file=/src/index.js

    Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels