• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it Possible to have the API Manager Cache Results when Query String Arguments Are Passed?

Explorer ,
Feb 14, 2018 Feb 14, 2018

Copy link to clipboard

Copied

I have a resource I have set up in one of my APIs, which the user may call with different arguments to augment the result set. For example, the user may want to pull back all of the objects in the database. In this case, no arguments are sent and all items are returned. But, they may also want a specific category and they may want to limit the results to a certain number. If they provide a query string argument for category and another for limit, the web service responds accordingly. They may also want to retrieve just one record. If they pass an ID for the record, the web service just pulls back that one record.

The trouble comes in when I implement caching for the API. After the response is cached for any set of arguments, it doesn't matter if I change the arguments, it still only pulls back the cached result set it originally returned when the cache was set.

Is there any way I can get it to behave more like query caching in ColdFusion, where it will cache separate result sets when different arguments are passed?

UPDATE: After looking more closely at RESTful standards and practices, I decided to give this a try as a POST method, passing a JSON string with the filter data I need for this query. I thought that might help with the caching issue, but it doesn't seem to have made a difference. Whatever parameters I send in JSON, it sends back the data it cached on the first attempt to the endpoint.

Any help or suggestions are appreciated here.

Views

296

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Feb 19, 2018 Feb 19, 2018

I've got this one figured out. There are a couple of things to keep in mind.

1. When caching is set at the resource level and parameters are sent via the URL, it doesn't seem to cache different results based on the parameters.

2. When caching is set at both the query level in your CF code and in the API Manager, the results can vary and be unpredictable.

3. If you remove caching at the query level in your CF code, and only have it enabled in the API Manager, it works properly when:

3a. You define a

...

Votes

Translate

Translate
Explorer ,
Feb 19, 2018 Feb 19, 2018

Copy link to clipboard

Copied

LATEST

I've got this one figured out. There are a couple of things to keep in mind.

1. When caching is set at the resource level and parameters are sent via the URL, it doesn't seem to cache different results based on the parameters.

2. When caching is set at both the query level in your CF code and in the API Manager, the results can vary and be unpredictable.

3. If you remove caching at the query level in your CF code, and only have it enabled in the API Manager, it works properly when:

3a. You define a variable value for the resource, such as /{id} and then pass the ID - it will return proper results

3b. You use a POST resource to pass unpredictable filter data via JSON

In my case, my users can filter the listing by category and whether the item is marked as "featured", and they are also able to specify a limit to the number of records which come back. None of these is required, so they could send whichever combination of these filters they choose. And now the caching is working as we would expect, so that's a win.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation