API Connect

  • 1.  Caching information in API connect

    Posted Mon April 19, 2021 10:23 AM
    Hello Community

    We are evaluating a possible option of caching some reusable backend data in API connect so that it can be used across multiple APIs. I know that the invoke policy has caching capabilities however out back side call is POST call and returns an ID token in response. I want to avoid writing an API proxy between the business API invoke and the backend service just to translate the operations to make use of the invoke policy caching. 

    I can see some custom policies in github that may be able to do it but we are also planning migrating from v5 to v10 in near future so I do not want to use the policy as it will not working in V10.

    I would like to hear some advice on the way forward.


    Regards

    ------------------------------
    Vaibhav Mehra
    ------------------------------


  • 2.  RE: Caching information in API connect

    Posted Mon August 23, 2021 08:26 AM
    Any suggestions from anyone

    @Hermann Stamm-Wilbrandt

    ------------------------------
    Vaibhav Mehra
    ------------------------------



  • 3.  RE: Caching information in API connect

    IBM Select
    Posted Mon August 23, 2021 08:41 AM
    Hi @Vaibhav Mehra -
    API Connect does allow mechanism to cache POST call response. ​You will just need to add 'cache-putpost-response: true' into your invoke policy (in the source yaml).

    Invoke (invoke) - IBM Documentation
     



    ------------------------------
    Romil Garg
    ------------------------------



  • 4.  RE: Caching information in API connect

    Posted Mon August 23, 2021 11:18 AM
    Thanks @Romil Garg

    My backend API response contains a cache-control header value as public, max-age=300 and my calling API invoke config is as mentioned below but I still get a fresh response from the backend on every call.

    invoke:
    title: invoke-base
    timeout: 90
    verb: POST
    cache-response: time-to-live
    cache-putpost-response: true
    stop-on-error:
    - null
    version: 1.0.0
    target-url: 'https://somehost:port/vm-cache-api/login'
    cache-key: ''
    cache-ttl: 200


    Any suggestions?

    Regards
    Vaibhav Mehra
    ​​

    ------------------------------
    Vaibhav Mehra
    ------------------------------



  • 5.  RE: Caching information in API connect

    IBM Select
    Posted Mon August 23, 2021 11:43 AM
    Are you using a dynamic target URL (path or query)?  If so, you might want to use a cache key.

    ------------------------------
    Romil Garg
    ------------------------------



  • 6.  RE: Caching information in API connect

    Posted Mon August 23, 2021 11:54 AM
    Hi @Romil Garg

    I assume you are referring to the URL configure in the invoke policy of the front side API. If yes then I can confirm that I am using a static URL.


    ​Regards​

    ------------------------------
    Vaibhav Mehra
    ------------------------------



  • 7.  RE: Caching information in API connect

    IBM Select
    Posted Mon August 23, 2021 12:01 PM
    Yes, the one you are using in your Invoke, the URL of your backend login API. If you are using anything dynamic in the URL like form body, path parameter or query parameters, then it will not cache the information. I suggest testing it with a static cache key.

    ------------------------------
    Romil Garg
    ------------------------------



  • 8.  RE: Caching information in API connect

    Posted Mon August 23, 2021 02:02 PM
    Thanks @Romil Garg

    I have submitted a PMR and will keep this thread updated.

    Regards
    Vaibhav​​​​

    ------------------------------
    Vaibhav Mehra
    ------------------------------



  • 9.  RE: Caching information in API connect

    Posted Tue August 31, 2021 03:07 AM
    The PMR finally helped. Apparently datapower does not cache invoke policy responses if the request contains Authorization header. removed the auth headers and it workes.

    Regards
    Vaibhav

    ------------------------------
    Vaibhav Mehra
    ------------------------------