@@ -37,71 +37,40 @@ const (
3737)
3838
3939var (
40- // TODO: add a helper function for get methods.
41- prefixCacheBlockNumber = getPrefixCacheBlockNumber ()
42- prefixCacheBlockSize = getPrefixCacheBlockSize ()
43- prefixCacheEvictionInterval = getPrefixCacheEvictionInterval ()
44- prefixCacheEvictionDuration = getPrefixCacheEvictionDuration ()
40+ prefixCacheBlockNumber = getEnvValueOrDefault ("AIBRIX_PREFIX_CACHE_BLOCK_NUMBER" , defaultPrefixCacheBlockNumber )
41+ prefixCacheBlockSize = getEnvValueOrDefault ("AIBRIX_PREFIX_CACHE_BLOCK_SIZE" , defaultPrefixCacheBlockSize )
42+ prefixCacheEvictionInterval = getEnvDurationOrDefault ("AIBRIX_PREFIX_CACHE_EVICTION_INTERVAL_SECONDS" , defaultPrefixCacheEvictionInternalInSec , time .Second )
43+ prefixCacheEvictionDuration = getEnvDurationOrDefault ("AIBRIX_PREFIX_CACHE_EVICTION_DURATION_MINS" , defaultPrefixCacheEvictionDurationInMins , time .Minute )
4544)
4645
47- func getPrefixCacheBlockNumber ( ) int {
48- value := utils .LoadEnv ("AIBRIX_PREFIX_CACHE_BLOCK_NUMBER" , "" )
46+ func getEnvValueOrDefault ( envKey string , defaultValue int ) int {
47+ value := utils .LoadEnv (envKey , "" )
4948 if value != "" {
5049 intValue , err := strconv .Atoi (value )
5150 if err != nil || intValue <= 0 {
52- klog .Infof ("invalid AIBRIX_PREFIX_CACHE_BLOCK_NUMBER : %s, falling back to default" , value )
51+ klog .Infof ("invalid %s : %s, falling back to default" , envKey , value )
5352 } else {
54- klog .Infof ("using AIBRIX_PREFIX_CACHE_BLOCK_NUMBER env value for prefix cache block number : %d" , intValue )
53+ klog .Infof ("using %s env value: %d" , envKey , intValue )
5554 return intValue
5655 }
5756 }
58- klog .Infof ("using default prefix cache block number : %d" , defaultPrefixCacheBlockNumber )
59- return defaultPrefixCacheBlockNumber
57+ klog .Infof ("using default %s : %d" , envKey , defaultValue )
58+ return defaultValue
6059}
6160
62- func getPrefixCacheBlockSize () int {
63- value := utils .LoadEnv ("AIBRIX_PREFIX_CACHE_BLOCK_SIZE" , "" )
61+ func getEnvDurationOrDefault ( envKey string , defaultValue int , unit time. Duration ) time. Duration {
62+ value := utils .LoadEnv (envKey , "" )
6463 if value != "" {
6564 intValue , err := strconv .Atoi (value )
6665 if err != nil || intValue <= 0 {
67- klog .Infof ("invalid AIBRIX_PREFIX_CACHE_BLOCK_SIZE : %s, falling back to default" , value )
66+ klog .Infof ("invalid %s : %s, falling back to default" , envKey , value )
6867 } else {
69- klog .Infof ("using AIBRIX_PREFIX_CACHE_BLOCK_SIZE env value for prefix cache block size: %d" , intValue )
70- return intValue
71- }
72- }
73- klog .Infof ("using default prefix cache block size: %d" , defaultPrefixCacheBlockSize )
74- return defaultPrefixCacheBlockSize
75- }
76-
77- func getPrefixCacheEvictionInterval () time.Duration {
78- value := utils .LoadEnv ("AIBRIX_PREFIX_CACHE_EVICTION_INTERVAL_SECONDS" , "" )
79- if value != "" {
80- intValue , err := strconv .Atoi (value )
81- if err != nil || intValue <= 0 {
82- klog .Infof ("invalid AIBRIX_PREFIX_CACHE_EVICTION_INTERVAL_SECONDS: %s, falling back to default" , value )
83- } else {
84- klog .Infof ("using AIBRIX_PREFIX_CACHE_EVICTION_INTERVAL_SECONDS env value for prefix cache eviction interval: %d ms" , intValue )
85- return time .Duration (intValue ) * time .Second
86- }
87- }
88- klog .Infof ("using default prefix cache eviction interval: %d ms" , defaultPrefixCacheEvictionInternalInSec )
89- return defaultPrefixCacheEvictionInternalInSec * time .Second
90- }
91-
92- func getPrefixCacheEvictionDuration () time.Duration {
93- value := utils .LoadEnv ("AIBRIX_PREFIX_CACHE_EVICTION_DURATION_MINS" , "" )
94- if value != "" {
95- intValue , err := strconv .Atoi (value )
96- if err != nil || intValue <= 0 {
97- klog .Infof ("invalid AIBRIX_PREFIX_CACHE_EVICTION_DURATION_MINS: %s, falling back to default" , value )
98- } else {
99- klog .Infof ("using AIBRIX_PREFIX_CACHE_EVICTION_DURATION_MINS env value for prefix cache eviction duration: %d ms" , intValue )
100- return time .Duration (intValue ) * time .Minute
68+ klog .Infof ("using %s env value: %d" , envKey , intValue )
69+ return time .Duration (intValue ) * unit
10170 }
10271 }
103- klog .Infof ("using default prefix cache eviction duration : %d mins " , defaultPrefixCacheEvictionDurationInMins )
104- return defaultPrefixCacheEvictionDurationInMins * time . Minute
72+ klog .Infof ("using default %s : %d" , envKey , defaultValue )
73+ return time . Duration ( defaultValue ) * unit
10574}
10675
10776type PrefixHashTable struct {
0 commit comments