Comments (8)
Update: Good News! (for me)
this was failing with a cache miss
[policy xml removed for brevity]
<cache-lookup-value key="@("itemnumber" + (string)context.Variables["itemNumber"])" variable-name="itemNumberJson" caching-type="internal" />
<cache-store-value caching-type="internal" key="@("itemnumber" + (string)context.Variables["itemNumber"])"
this now works
<cache-lookup-value key="@((string)context.Variables["itemNumber"])" variable-name="itemNumberJson" caching-type="internal" />
<cache-store-value caching-type="internal" key="@((string)context.Variables["itemNumber"])" />
something about the concatenation it didn't like. It wasn't failing on the "cache-store-value" section, it was storing it, just on the "cache-lookup-value" section, never found it until i removed the prepended constant
from api-management-policy-snippets.
I am having the same issue with a 2_ prefix being added. However I'm not doing string concatenation... Did we ever figure out root cause here?
from api-management-policy-snippets.
@gabrielbustamante @jonathandbyrd
Good news from my side! I figured out that my issue was not the "2_" prefix at all. Apparently that is just how APIM works behind the scenes: they always prepend the "2_'. This is fine I guess, but their logs/docs should really account for this more clearly. In debugging my issue, this seeming issue was a very time-consuming false-positive.
My actual issue was redis firewall rules. I had added a firewall rule to allow my PC which inadvertently ended up blocking APIM. The apim trace logs let me down again by saying "Value stored in cache" when indeed it had been blocked by a firewall rule.
{"source":"cache-store-value","timestamp":"2021-10-01T21:03:56.4601530Z","elapsed":"00:00:00.2815404","data":{"message":"Value stored in cache.","key":"2__my_key_name","value":"my_json_paylod"","timeout":"06:00:00"}}
TLDR: Don't trust apim trace. It's useful, but certainly not definitive.
from api-management-policy-snippets.
@maksimkim please comment.
from api-management-policy-snippets.
@harre096 @vladvino @jonathandbyrd
i have the same problem, always that i use this "cache-lookup-value", for some reason the key has a pre-pended "2_", someone with the same problem?
if i check redis from my backend service (.net) i can matching the values, but if i call redis directly from my Azure gateway, this prefix "2_" always appear
from api-management-policy-snippets.
In my case, cache-store-value
is not working, so there is always cache miss. What could be the reason?
Policy:
<set-variable name="partnerInfo" value="@{
var partnerAccountNumber = context.Variables["partnerAccountNumber"];
var partnerRegion = context.Variables["partnerRegion"];
var partnerType = context.Variables["partnerType"];
return $"{partnerAccountNumber}:{partnerRegion}:{partnerType}";
}"/>
<cache-store-value caching-type="internal" key="@((string)context.Variables["id"])" value="@((string)context.Variables["partnerInfo"])" duration="10000"/>
Trace:
{
"source": "cache-lookup-value",
"timestamp": "2022-03-10T21:58:24.6068604Z",
"elapsed": "00:00:00.0005265",
"data": "No appropriate cache found for provided policy configuration. Policy execution will be skipped."
},
{
"source": "cache-lookup-value",
"timestamp": "2022-03-10T21:58:24.6068650Z",
"elapsed": "00:00:00.0005312",
"data": {
"message": "Cache lookup resulted in a miss, variable will not be set.",
"key": "2_7c486765553047aca4f1088c0e5b1b8e",
"variableName": "partnerInfo"
}
}
/
/
/
{
"source": "set-variable",
"timestamp": "2022-03-10T21:58:25.2051048Z",
"elapsed": "00:00:00.5987711",
"data": {
"message": "Context variable was successfully set.",
"name": "partnerInfo",
"value": "674756756:EMEA:CUSTOMER"
}
},
{
"source": "cache-store-value",
"timestamp": "2022-03-10T21:58:25.2051357Z",
"elapsed": "00:00:00.5988023",
"data": "No appropriate cache found for provided policy configuration. Policy execution will be skipped."
}
P.S.: My instance is on Developer tier
from api-management-policy-snippets.
In my case,
cache-store-value
is not working, so there is always cache miss. What could be the reason?Policy:
<set-variable name="partnerInfo" value="@{ var partnerAccountNumber = context.Variables["partnerAccountNumber"]; var partnerRegion = context.Variables["partnerRegion"]; var partnerType = context.Variables["partnerType"]; return $"{partnerAccountNumber}:{partnerRegion}:{partnerType}"; }"/> <cache-store-value caching-type="internal" key="@((string)context.Variables["id"])" value="@((string)context.Variables["partnerInfo"])" duration="10000"/>
Trace:
{ "source": "cache-lookup-value", "timestamp": "2022-03-10T21:58:24.6068604Z", "elapsed": "00:00:00.0005265", "data": "No appropriate cache found for provided policy configuration. Policy execution will be skipped." }, { "source": "cache-lookup-value", "timestamp": "2022-03-10T21:58:24.6068650Z", "elapsed": "00:00:00.0005312", "data": { "message": "Cache lookup resulted in a miss, variable will not be set.", "key": "2_7c486765553047aca4f1088c0e5b1b8e", "variableName": "partnerInfo" } } / / / { "source": "set-variable", "timestamp": "2022-03-10T21:58:25.2051048Z", "elapsed": "00:00:00.5987711", "data": { "message": "Context variable was successfully set.", "name": "partnerInfo", "value": "674756756:EMEA:CUSTOMER" } }, { "source": "cache-store-value", "timestamp": "2022-03-10T21:58:25.2051357Z", "elapsed": "00:00:00.5988023", "data": "No appropriate cache found for provided policy configuration. Policy execution will be skipped." }
P.S.: My instance is on Developer tier
I am facing the same problem. I use an existing redis cache and I'd like to simply get the value of one entry.
I have not found a way to avoid this prefix.
It would be nice to be able to reuse an existing Redis Cache data.
I believe this only works with an internal cache. When using Redis, the actual result in there shows this "2_" prefix.
from api-management-policy-snippets.
I am facing the same issue when i am using cache lookup or cache store using internal cache. any resolutions yet?
from api-management-policy-snippets.
Related Issues (20)
- Question : Do you have an example of setting a policy for token validation provided by PING Federation?
- Azure Redis Cache Prefixed with 2_
- Encryption Policy not working HOT 2
- Filter on IP Address when using Application Gateway.policy.xml HOT 1
- Azure OpenAI + random load balancer policy HOT 3
- How to use set-body template="liquid" to access request body json attribute? HOT 1
- No byte[] decrypt / encrypt in api-management-policy-snippets/examples /Encrypt data using expressions.policy.xml HOT 1
- Aren't APIM's inbound policies able to read Redis Cache keys set externally? HOT 2
- Invalid Policy Expression Sample HOT 1
- Policy Fragment does not support Authentication policy HOT 3
- APIM manager API policy creation using azuredevops pipeline HOT 1
- Azuredevops resource kit for azure Api management will work with Azure CLI and bash? HOT 1
- Azure Blob SAS Token generated using APIM failing intermittent at Blob
- is there any way to export the effective policy assigned to api and operation level to an xml file?
- is there any way to create an Azure policy Definition for API management with IP filter restrictions?
- Allow all IP address
- Incorrect Sample | Call out to an HTTP endpoint and cache the response.policy.xml
- This repo is missing important files
- PolicyFragment ARM Template deployment fails - The policy fragment is not a valid XML: HOT 1
- Add Policy Fragment Examples
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api-management-policy-snippets.