added caching for /devops/connector-method-names

This commit is contained in:
simonredfern 2025-11-24 01:10:06 +01:00
parent ac3b585628
commit 2a69ee5ae1
2 changed files with 21 additions and 3 deletions

View File

@ -244,6 +244,11 @@ MappedMetrics.stable.boundary.seconds=600
# Default: 3600 seconds (1 hour) - Provider list changes infrequently
getDistinctProviders.cache.ttl.seconds=3600
## Connector Method Names Cache Configuration
# Cache TTL for GET /devops/connector-method-names endpoint (list of connector methods)
# Default: 3600 seconds (1 hour) - Connector methods only change on deployment
getConnectorMethodNames.cache.ttl.seconds=3600
## You can use a no config needed h2 database by setting db.driver=org.h2.Driver and not including db.url
# See the README for how to use the H2 browser / console.

View File

@ -1142,9 +1142,22 @@ trait APIMethods600 {
for {
(Full(u), callContext) <- authenticatedAccess(cc)
_ <- NewStyle.function.hasEntitlement("", u.userId, canGetMethodRoutings, callContext)
connectorName = APIUtil.getPropsValue("connector", "mapped")
connector = code.bankconnectors.Connector.getConnectorInstance(connectorName)
methodNames = connector.callableMethods.keys.toList
// Fetch connector method names with caching
methodNames <- Future {
/**
* Cache key will be auto-generated by macro.
* Connector methods rarely change (only on deployment), so we cache for a long time.
*/
var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
val cacheTTL = APIUtil.getPropsAsIntValue("getConnectorMethodNames.cache.ttl.seconds", 3600)
CacheKeyFromArguments.buildCacheKey {
Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(cacheTTL seconds) {
val connectorName = APIUtil.getPropsValue("connector", "mapped")
val connector = code.bankconnectors.Connector.getConnectorInstance(connectorName)
connector.callableMethods.keys.toList
}
}
}
} yield {
(JSONFactory600.createConnectorMethodNamesJson(methodNames), HttpCode.`200`(callContext))
}