Retrieve All keys from KeyValue Map and store to Cache

Not applicable

Hi,

I have a KeyValueMap created at Environment Level. I would like to create a sharedFlow that reads the KeyValueMap and populates it into a Cache so all the api proxies will read from the Cache and not the KVM.

Is there any proposed policy to Retrieve all the key/value pairs from the KVM in a single go

Thanks in advance

1 7 568
7 REPLIES 7

You might THINK you want to do that, but you probably don't.

The KeyValueMapOperations policy with Action:GET will populate a cache, so that subsequent reads will read from cache until the expiry. So you shouldn't need to do the work you are describing, to optimize performance.

You *could* use a sharedflow to just read the KVM, which will implicitly populate the cache. But there is no policy to "retrieve all the values".

If it is super important to pre-populate the Cache with values, then you could populate a single KVM entry with a JSON payload, then shred the JSON payload and populate individual cache entries for each of the JSON properties.... You could do that in a loop using the nodejs target and the apigee-access module.

But honestly this seems like a lot of work for very little advantage. The initial KVM read will take single-digit milliseconds, let's guess around 5ms. Subsequent KVM reads will take much less than 1ms. In either case you're not gaining a lot, by introducing this additional complexity.

Thanks for coming back...I was actually referring to another communitu post with respect to Caching of KVM community link

But your proposal is different from what it said...Has anything changed?

I don't know if anything has changed, but my proposal is the right one!

Not applicable

Hi @Deepa , Thanks for bringing it up.


I see that @Ozan Seymen wrote that article in May but looks like some enhancements were made in June as per http://docs.apigee.com/release-notes/content/160615-ui-apigee-edge-public-cloud-release-notes#Expiry...

With the enhanced policy you can cache keys in-memory and you don't need to define explicit cache. Whenever you want to update the cache, you can PUT "PUT operation writes keys/values to the specified KVM. If the PUT writes to a key that already exists in cache, that cache is immediately refreshed and now holds the new value for the number of seconds specified in the policy's <ExpiryTimeInSecs> element." which is what Ozan explained but with explicit cache.

Hi @Ozan Seymen, any comments?

Thanks for the heads-up Maruti

Hi @Deepa

The community post for caching KVM values has been written when there were no built-in method for caching values. I have updated the community post but also noted some caveats and differences between the in-built implementation and the pattern explained in the post. Please consider the differences before going forward with any of those patterns as in-built method may not be the right way for you (yet).

@Ozan Seymen Thanks for the clarification. This helps and avoids confusion.