Question

We have different services deployed in DSS and we have a different way of caching:

  • no cache
  • 1 hour cache
  • 1 day cache

Is there any way to set this caching directly to each dbs file without using the administration console?

Another way would be to set these three caches through a configuration file and then to refers to them from the dbs files.

The solution we are looking for, is without using the administration console.

Was it helpful?

Solution

It is indeed possible to configure caching for dataservices via a configuration file without using the management console. Each dataservice is deployed as form of a axis2 service. Therefore you can use the "services.xml" file which you would typically use to configure axis2 service related parameters, with dataservices too with a slight modification. That is, if the name of your dataservice is "TestDS" then you have to name your services.xml file as "TestDS_services.xml" and place it inside the dataservices deployment directory which can be located at "DSS_HOME/repository/deployment/server/dataservices". Then you can include a caching policy having your own values as the parameters inside the aforementioned configuration file. Also it is important to note that, you can engage caching in three levels for a dataservies namely, per service group/per service/per operation.

A sample services.xml is show below.

<serviceGroup>
    <service name="TestDS">
        <!--parameter name="ServiceObjectSupplier">org.apache.axis2.engine.DefaultObjectSupplier</parameter-->
    <Description>Enabling caching through sevices.xml</Description>

    <operation name="op1">
        <messageReceiver class="org.wso2.carbon.dataservices.core.DBInOutMessageReceiver"/>
    <module ref="wso2caching"/>
        <wsp:Policy
            wsu:Id="WSO2CachingPolicy"
            xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsch:CachingAssertion xmlns:wsch="http://www.wso2.org/ns/2007/06/commons/caching">
        <wsp:Policy>
            <wsp:All>
            <wsch:XMLIdentifier>org.wso2.caching.digest.DOMHASHGenerator</wsch:XMLIdentifier>
            <wsch:ExpireTime>70000</wsch:ExpireTime>
            <wsch:MaxCacheSize>1000</wsch:MaxCacheSize>
            <wsch:MaxMessageSize>1000</wsch:MaxMessageSize>
            </wsp:All>
        </wsp:Policy>
        </wsch:CachingAssertion>
        </wsp:Policy>
    </operation>

    <operation name="op2">
        <messageReceiver class="org.wso2.carbon.dataservices.core.DBInOutMessageReceiver"/>
    <module ref="wso2caching"/>
        <wsp:Policy
            wsu:Id="WSO2CachingPolicy"
            xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsch:CachingAssertion xmlns:wsch="http://www.wso2.org/ns/2007/06/commons/caching">
        <wsp:Policy>
            <wsp:All>
            <wsch:XMLIdentifier>org.wso2.caching.digest.DOMHASHGenerator</wsch:XMLIdentifier>
            <wsch:ExpireTime>600000</wsch:ExpireTime>
            <wsch:MaxCacheSize>1000</wsch:MaxCacheSize>
            <wsch:MaxMessageSize>1000</wsch:MaxMessageSize>
            </wsp:All>
        </wsp:Policy>
        </wsch:CachingAssertion>
        </wsp:Policy>
    </operation>
        <operation name="op3">
        </operation>

    </service>
  </serviceGroup>

After placing your "data_service_name"_services.xml file inside the aforesaid directory, you have to comment out the following entry from the axis2.xml configuration file that can be located at "DSS_HOME/repository/conf" directory.

<listener class="org.wso2.carbon.core.deployment.DeploymentInterceptor">

Now you're good to go with your deployment. Restart the server and you'll be able to get the aforementioned functionality working.

NOTE: You would also want to be informed that a lot of improvements have been done on this space in DSS for our immediate upcoming DSS release. (DSS 3.0.0).

Regards, Prabath

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top