'Azure API Management: cache-store not honoring duration
In Azure APIM, I have an API that queries a SQL table. I created a cache policy for the API to expire after 300 sec. I then created a script to invoke the API every 10 min, and traced the API response and SQL Server db.
For almost an hour, all calls to the API were cache hits - only two cache misses were recorded in App Insights (the first call and last call at the +50 min mark), and only two sql calls were recorded in my sql profiler trace (the first and last call).
I was expecting to see a cache-miss almost every time, but did not. Am I misunderstanding cache-store?
Here is the policy definition:
<policies>
<inbound>
<base />
<cache-lookup vary-by-developer="false" vary-by-developer-groups="false" must-revalidate="true" downstream-caching-type="none" caching-type="internal">
<vary-by-query-parameter>xxxxx</vary-by-query-parameter>
</cache-lookup>
</inbound>
<backend>
<base />
</backend>
<outbound>
<cache-store duration="300" />
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Solution 1:[1]
Can you please try the modified outbound policy:
<cache-store duration="10" cache-response="true" />
cache-response:
Set to true to cache the current HTTP response. If the attribute is omitted or set to false, only HTTP responses with the status code 200 OK are cached.
This does also mean, you have to check your current response codes 200/400/404/500/... Maybe there was most of the time a 404 response, which was not cached.
Solution 2:[2]
Prerequisite: Pod should be installed.
Run the following commands in the terminal to install cocoapod.Sudo gem install cocoapods
Check if installation is successful by running the command.pod --version
Official cocoapods installation guide
Installation troubleshooting
Steps:
First we have to create an xcode framework that to be hosted in Cocoapods.org.
To share the framework functionalities to the public, that is, to be accessible outside the module, we have to make the classes, structures, methods of the framework public.
Then, we have to push the framework to github.
Create a github tag (Version number) and push the tag.
We have to create a podspec locally and later (step 8) upload it in the same github directory of the framework. To create a podspec locally run terminal command:
pod spec create FrameworkNameDescribe the podspec file accordingly. Podspec guide
Example podspec:Pod::Spec.new do |spec| spec.name = 'Reachability' # name of the framework spec.version = '3.1.0' # same as github tag version spec.license = { :type => 'BSD' } # can be :type=> ‘MIT’ spec.homepage = 'https://github.com/tonymillion/Reachability' # Website with details about pod or github repository link spec.authors = { 'Tony Million' => '[email protected]' } # name & email address of the framework author spec.platform = :ios, "13.0" spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.' spec.source = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' } # url to clone the framework, tag may be same as spec.version spec.source_files = 'Reachability.{h,m}' # add the regex to access all the files for the framework ex: ‘FrameworkName/**/*.{h,m,swift}’ endSave the podspec and then test (lint) the podspec.
Terminal command:pod spec lint
Warnings can be allowed:pod spec lint --allow-warningsAfter the podspec passes validation, update the remote repository by pushing the podspec to github repository. (add -> commit -> push)
To upload the pod in cocoapods.org to be accessible publicly, we have create a pod session. For this, first we have to register to cocoapods if we are not registered yet.
Terminal command:pod trunk register email username --description=’macbook pro’
Then a verification email will be sent to us that we have to verify.Create the session. Terminal command:
pod trunk meThen we will push the pod. Terminal command:
pod trunk push FrameworkName.podspec
Warnings can be allowed :pod trunk push FrameworkName.podspec --allow-warnings
It will validate (lint) the podspec file.It will show a success message if everything goes right with a cocoapods.org link of the framework.
Push the updated local repository to the remote repository. (add -> commit -> push)
Following the URL we get from “12”, we can see our framework being hosted in cocoapods.org
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Markus Meyer |
| Solution 2 | Alexander |
