Skip to content

Commit

Permalink
don't expire dynmaic floor feature related fields in memory cache (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
shunj-nb authored Jul 25, 2023
1 parent e36f475 commit fdf52af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/db/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ func SetCache(key string, val interface{}) {
memCache.Set(key, val, cache.DefaultExpiration)
}
}

func SetCacheWithNoExpiration(key string, val interface{}) {
if MemCacheInit {
memCache.Set(key, val, cache.NoExpiration)
}
}
8 changes: 4 additions & 4 deletions pkg/modules/dynamic_floor/module/floor_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (eval *FloorEvaluator) getStrategyRR(reqeustLevelKey string) (*roundrobin.R
}

func (eval *FloorEvaluator) setStrategyRR(reqeustLevelKey string, rr *roundrobin.RoundRobin) {
db.SetCache(generateStrategyRRKey(reqeustLevelKey), rr)
db.SetCacheWithNoExpiration(generateStrategyRRKey(reqeustLevelKey), rr)
}

func (eval *FloorEvaluator) getBucketFloorInfo(dimensionKey string, strategy string) (BucketsFloorInfo, bool) {
Expand All @@ -179,11 +179,11 @@ func (eval *FloorEvaluator) getBucketFloorInfo(dimensionKey string, strategy str
}

func (eval *FloorEvaluator) setGlobalFloorInfo(dimensionKey string, currentFloorInfo CurrentFloorInfo) {
db.SetCache(generateGlobalKey(dimensionKey), currentFloorInfo)
db.SetCacheWithNoExpiration(generateGlobalKey(dimensionKey), currentFloorInfo)
}

func (eval *FloorEvaluator) setBucketFloorInfo(dimensionKey string, strategy string, bucketsFloorInfo BucketsFloorInfo) {
db.SetCache(generateBucketKey(dimensionKey, strategy), bucketsFloorInfo)
db.SetCacheWithNoExpiration(generateBucketKey(dimensionKey, strategy), bucketsFloorInfo)
}

func (eval *FloorEvaluator) getDimensionKeyList() DimensionList {
Expand All @@ -202,7 +202,7 @@ func (eval *FloorEvaluator) updateDimensionKeyList(dimensionKey string) {
updated[dimension] = 1
}
}
db.SetCache(DIMENSION_LIST_CACHE_KEY, updated)
db.SetCacheWithNoExpiration(DIMENSION_LIST_CACHE_KEY, updated)
}

func (eval *FloorEvaluator) GetCurrentFloorDelta(req *openrtb_ext.RequestWrapper, imp *openrtb_ext.ImpWrapper, bidder string) float64 {
Expand Down

0 comments on commit fdf52af

Please sign in to comment.