{ DreamFactory: 'Blog' }

New Feature - Remote Web Service Caching

Posted by Todd Appleton

Fri, Nov 21, 2014

ToddAppleton

The DreamFactory Services Platform (DSP) supports adding any number of services to each DSP instance. These services are then accessible from the REST API that's built in to every DSP. Often these services are either a database or file storage but there's another service type called 'Remote Web Service'. This could be any service that has a REST API supporting JSON or XML document exchange. See this blog post for an overview of how remote web services are configured and called.

In version 1.8.1 we added a new feature to remote web services. Now you can set up caching on your DSP for any remote web service. Here are a few cases where that might be desirable.

  • service has strict usage limits or usage fees
  • returned data does not change often
  • service is slow or unreliable

The benefits of this caching are pretty clear. The cached data is returned quickly without the extra hop from the DSP to the service. The number of API calls to the service can be greatly reduced, saving you bandwidth and money. Let's look at how to set this up for a remote web service that I've added to my DSP.  I have a service named 'edmunds' that accesses vehicle information at edmunds.com. To add caching to this service, select it in the Services tab of the DSP admin console and go to the caching section.

Enable Caching

The first step is to enable caching for the service by checking the Enabled checkbox. Also you should set the Time To Live in seconds. If you want the cache to last for 5 minutes you would set it to 300.

caching_1

Set Query Parameters to Exclude

If your client application sends query parameters as part of the REST API call to invoke the service, the default behavior is to pass all of these parameters through to the service and include them in the caching key. The Exclude Client Parameters section allows you to specify which query parameters should NOT be sent or included in the caching key. In our example we'll remove the '_' added by jQuery when it sent the request to the DSP. Checking 'From Outbound' means that the parameter will be removed from the client request before the DSP calls the service. Checking 'From Caching Key' means that the parameter will not be included in the caching key.

caching_2

Add More Parameters

The query parameters expected by the remote service are normally stored in the service configuration under "Add More Parameters". These are the parameters that should be added to the client request before the DSP calls out to the actual remote service on the client's behalf. For our service we have a parameter for format and an API key. All parameters created here are stored securely on your DSP. Parameter values can also include lookup keys. "To Outbound' is checked because we want to add these parameters to each outbound service call. 'To Caching Key' is checked because we also want these parameters included in the caching key. If these parameters are constants, you don't really need to add them to the caching key, but it won't hurt anything.

caching_3

Clearing the Cache

If you need to manually clear the cache for some reason, you can do that from the DSP admin console by clicking the wrench icon in the upper right corner and selecting "Flush Platform Cache'.

caching_4

Give this new caching feature a try and let us know if you have any questions or comments. We're always looking for feedback to make the product better.

Get started with DreamFactory with a free hosted DreamFactory development environment. Or, download and run it on the server, cloud, or desktop of your choice.

Weekly Digest