mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:26:51 +00:00
caching get providers
This commit is contained in:
parent
afb20017e5
commit
6cb4652bb8
@ -239,6 +239,11 @@ MappedMetrics.cache.ttl.seconds.getStableMetrics=86400
|
||||
# 10 minutes - Metrics older than this are considered stable
|
||||
MappedMetrics.stable.boundary.seconds=600
|
||||
|
||||
## Provider List Cache Configuration
|
||||
# Cache TTL for GET /providers endpoint (list of authentication providers)
|
||||
# Default: 3600 seconds (1 hour) - Provider list changes infrequently
|
||||
getDistinctProviders.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.
|
||||
|
||||
@ -27,14 +27,19 @@ TESOBE (http://www.tesobe.com/)
|
||||
package code.model.dataAccess
|
||||
|
||||
import java.util.Date
|
||||
import java.util.UUID.randomUUID
|
||||
|
||||
import code.api.Constant
|
||||
import code.api.cache.Caching
|
||||
import code.api.util.APIUtil
|
||||
import code.util.MappedUUID
|
||||
import com.openbankproject.commons.model.{User, UserPrimaryKey}
|
||||
import com.tesobe.CacheKeyFromArguments
|
||||
import net.liftweb.mapper._
|
||||
import net.liftweb.mapper.DB
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
/**
|
||||
* An O-R mapped "User" class that includes first name, last name, password
|
||||
*
|
||||
@ -125,9 +130,21 @@ object ResourceUser extends ResourceUser with LongKeyedMetaMapper[ResourceUser]{
|
||||
override def dbIndexes = UniqueIndex(provider_, providerId) ::super.dbIndexes
|
||||
|
||||
def getDistinctProviders: List[String] = {
|
||||
val sql = "SELECT DISTINCT provider_ FROM resourceuser ORDER BY provider_"
|
||||
val (_, rows) = DB.runQuery(sql, List())
|
||||
rows.flatten
|
||||
/**
|
||||
* Please note that "var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)"
|
||||
* is just a temporary value field with UUID values in order to prevent any ambiguity.
|
||||
* The real value will be assigned by Macro during compile time at this line of a code:
|
||||
* https://github.com/OpenBankProject/scala-macros/blob/master/macros/src/main/scala/com/tesobe/CacheKeyFromArgumentsMacro.scala#L49
|
||||
*/
|
||||
var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
|
||||
val cacheTTL = APIUtil.getPropsAsIntValue("getDistinctProviders.cache.ttl.seconds", 3600)
|
||||
CacheKeyFromArguments.buildCacheKey {
|
||||
Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(cacheTTL seconds) {
|
||||
val sql = "SELECT DISTINCT provider_ FROM resourceuser ORDER BY provider_"
|
||||
val (_, rows) = DB.runQuery(sql, List())
|
||||
rows.flatten
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,11 @@
|
||||
### Most recent changes at top of file
|
||||
```
|
||||
Date Commit Action
|
||||
TBD TBD Performance Improvement: Added caching to getProviders endpoint
|
||||
Added configurable caching with memoization to GET /obp/v6.0.0/providers endpoint.
|
||||
- Default cache TTL: 3600 seconds (1 hour)
|
||||
- Configurable via props: getDistinctProviders.cache.ttl.seconds
|
||||
- Significantly reduces database load for provider list lookups
|
||||
TBD TBD Changes to non stable endpoints: DevOps endpoint path updates
|
||||
Changed /dev-ops/ to /devops/ for all DevOps operational endpoints:
|
||||
- v5.1.0: /dev-ops/log-cache/LOG_LEVEL -> /devops/log-cache/LOG_LEVEL
|
||||
|
||||
Loading…
Reference in New Issue
Block a user