|
|
@@ -101,6 +101,9 @@ var defaultCreateCacheRatio = map[string]float64{
|
|
|
var cacheRatioMap map[string]float64
|
|
|
var cacheRatioMapMutex sync.RWMutex
|
|
|
|
|
|
+var createCacheRatioMap map[string]float64
|
|
|
+var createCacheRatioMapMutex sync.RWMutex
|
|
|
+
|
|
|
// GetCacheRatioMap returns the cache ratio map
|
|
|
func GetCacheRatioMap() map[string]float64 {
|
|
|
cacheRatioMapMutex.RLock()
|
|
|
@@ -119,6 +122,17 @@ func CacheRatio2JSONString() string {
|
|
|
return string(jsonBytes)
|
|
|
}
|
|
|
|
|
|
+// CreateCacheRatio2JSONString converts the create cache ratio map to a JSON string
|
|
|
+func CreateCacheRatio2JSONString() string {
|
|
|
+ createCacheRatioMapMutex.RLock()
|
|
|
+ defer createCacheRatioMapMutex.RUnlock()
|
|
|
+ jsonBytes, err := json.Marshal(createCacheRatioMap)
|
|
|
+ if err != nil {
|
|
|
+ common.SysLog("error marshalling create cache ratio: " + err.Error())
|
|
|
+ }
|
|
|
+ return string(jsonBytes)
|
|
|
+}
|
|
|
+
|
|
|
// UpdateCacheRatioByJSONString updates the cache ratio map from a JSON string
|
|
|
func UpdateCacheRatioByJSONString(jsonStr string) error {
|
|
|
cacheRatioMapMutex.Lock()
|
|
|
@@ -131,6 +145,18 @@ func UpdateCacheRatioByJSONString(jsonStr string) error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
+// UpdateCreateCacheRatioByJSONString updates the create cache ratio map from a JSON string
|
|
|
+func UpdateCreateCacheRatioByJSONString(jsonStr string) error {
|
|
|
+ createCacheRatioMapMutex.Lock()
|
|
|
+ defer createCacheRatioMapMutex.Unlock()
|
|
|
+ createCacheRatioMap = make(map[string]float64)
|
|
|
+ err := json.Unmarshal([]byte(jsonStr), &createCacheRatioMap)
|
|
|
+ if err == nil {
|
|
|
+ InvalidateExposedDataCache()
|
|
|
+ }
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
// GetCacheRatio returns the cache ratio for a model
|
|
|
func GetCacheRatio(name string) (float64, bool) {
|
|
|
cacheRatioMapMutex.RLock()
|
|
|
@@ -143,7 +169,9 @@ func GetCacheRatio(name string) (float64, bool) {
|
|
|
}
|
|
|
|
|
|
func GetCreateCacheRatio(name string) (float64, bool) {
|
|
|
- ratio, ok := defaultCreateCacheRatio[name]
|
|
|
+ createCacheRatioMapMutex.RLock()
|
|
|
+ defer createCacheRatioMapMutex.RUnlock()
|
|
|
+ ratio, ok := createCacheRatioMap[name]
|
|
|
if !ok {
|
|
|
return 1.25, false // Default to 1.25 if not found
|
|
|
}
|
|
|
@@ -159,3 +187,13 @@ func GetCacheRatioCopy() map[string]float64 {
|
|
|
}
|
|
|
return copyMap
|
|
|
}
|
|
|
+
|
|
|
+func GetCreateCacheRatioCopy() map[string]float64 {
|
|
|
+ createCacheRatioMapMutex.RLock()
|
|
|
+ defer createCacheRatioMapMutex.RUnlock()
|
|
|
+ copyMap := make(map[string]float64, len(createCacheRatioMap))
|
|
|
+ for k, v := range createCacheRatioMap {
|
|
|
+ copyMap[k] = v
|
|
|
+ }
|
|
|
+ return copyMap
|
|
|
+}
|