DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

DataPower Cache using Stylesheet

  • 1.  DataPower Cache using Stylesheet

    Posted Fri January 15, 2021 02:42 PM

    Hi there,

    I am trying to dynamically create cache policy in request URL before calling DP url open. This is to cache json response of POST request.

    I am trying below code in my stylesheet before making dp url open call.

    But it is not caching the response, However If i put it in xml manager cache policy, i can see cache entry in document status.

    Code-:

    <xsl:variable name="cachePolicy"> <allowCompression>on</allowCompression> <dcp:caching-policies xmlns:dcp="http://www.datapower.com/schemas/caching"> <dcp:caching-policy url-match="{$endpoint}" priority="128"> <dcp:fixed ttl="{$cachetime}" cache-backend-response="true" http-cache-validation="false" return-expired-document="false" restful-invalidation="false" cache-post-put-response="true" /> </dcp:caching-policy> </dcp:caching-policies> ' </xsl:variable> <dp:set-variable name="'var://service/mpgw/backend-config'" value="$cachePolicy" /> <xsl:variable name="response"> <dp:url-open target="{$endpoint}" http-method="post" http-headers="$headerValues" content-type="application/x-www-form-urlencoded" timeout="60" response="responsecode-binary" data-type="json"> <xsl:value-of select="$body" /> </dp:url-open> </xsl:variable>

    Can you please guide me what I am missing here.

    Many thanks



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: DataPower Cache using Stylesheet
    Best Answer

    Posted Tue January 19, 2021 01:17 PM

    Hi,

    few things stand out. The service variable var://service/mpgw/backend-config is wrong. It seems that there is an error in IBM Knowledge Center documentation. The correct variable is var://service/cache/dynamic-policies. If set the variable in the same stylesheet in which you are making the url-open call it doesn't work. Create another xform action before the url-open action and set the variable there.

    Also remove allowCompression element. That is part of backend-config definition, not a part of dynamic-policies.

    And if you want to cache POST/PUT responses, you'd probably want to set x-dp-cache-key header in your url-open request.

    --HP



    #DataPower
    #Support
    #SupportMigration


  • 3.  RE: DataPower Cache using Stylesheet
    Best Answer

    Posted Wed January 20, 2021 09:40 AM

    Hey HP,


    Thanks for you reply. Your given variable works now.


    I had added allowCompression because backend-config require it, without this it was given error.


    Many Thanks.








    #DataPower
    #Support
    #SupportMigration