Giter VIP home page Giter VIP logo

Comments (8)

jonathandbyrd avatar jonathandbyrd commented on August 11, 2024 1

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.

harre096 avatar harre096 commented on August 11, 2024 1

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.

harre096 avatar harre096 commented on August 11, 2024 1

@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.

vladvino avatar vladvino commented on August 11, 2024

@maksimkim please comment.

from api-management-policy-snippets.

gabrielbustamante avatar gabrielbustamante commented on August 11, 2024

@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.

thepolyglotter avatar thepolyglotter commented on August 11, 2024

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.

jvecc avatar jvecc commented on August 11, 2024

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.

UmairSyed avatar UmairSyed commented on August 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.