mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:46:49 +00:00
cache prefix for rate limits
This commit is contained in:
parent
de2997d782
commit
7b4f717ad4
@ -192,7 +192,7 @@ object RateLimitingUtil extends MdcLoggable {
|
||||
|
||||
RateLimitCounterState(calls, normalizedTtl, status)
|
||||
}
|
||||
private def createUniqueKey(consumerKey: String, period: LimitCallPeriod) = consumerKey + "_" + RateLimitingPeriod.toString(period)
|
||||
private def createUniqueKey(consumerKey: String, period: LimitCallPeriod) = "rl_counter_" + consumerKey + "_" + RateLimitingPeriod.toString(period)
|
||||
private def underConsumerLimits(consumerKey: String, period: LimitCallPeriod, limit: Long): Boolean = {
|
||||
|
||||
if (useConsumerLimits) {
|
||||
|
||||
@ -262,12 +262,7 @@ object MappedRateLimitingProvider extends RateLimitingProviderTrait {
|
||||
}
|
||||
|
||||
private def getActiveCallLimitsByConsumerIdAtDateCached(consumerId: String, currentDateWithHour: String): List[RateLimiting] = {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
// Cache key uses standardized prefix: rl_active_{consumerId}_{dateWithHour}
|
||||
// Create a proper Date object from the date_with_hour string (assuming 0 mins and 0 seconds)
|
||||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH")
|
||||
val localDateTime = LocalDateTime.parse(currentDateWithHour, formatter).withMinute(0).withSecond(0)
|
||||
@ -275,16 +270,14 @@ object MappedRateLimitingProvider extends RateLimitingProviderTrait {
|
||||
val instant = localDateTime.atZone(java.time.ZoneId.systemDefault()).toInstant()
|
||||
val date = Date.from(instant)
|
||||
|
||||
var cacheKey = (randomUUID().toString, randomUUID().toString, randomUUID().toString)
|
||||
CacheKeyFromArguments.buildCacheKey {
|
||||
Caching.memoizeSyncWithProvider(Some(cacheKey.toString()))(3600 second) {
|
||||
val cacheKey = s"rl_active_${consumerId}_${currentDateWithHour}"
|
||||
Caching.memoizeSyncWithProvider(Some(cacheKey))(3600 second) {
|
||||
RateLimiting.findAll(
|
||||
By(RateLimiting.ConsumerId, consumerId),
|
||||
By_<=(RateLimiting.FromDate, date),
|
||||
By_>=(RateLimiting.ToDate, date)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def getActiveCallLimitsByConsumerIdAtDate(consumerId: String, date: Date): Future[List[RateLimiting]] = Future {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user