func (cacheRepository *CacheRepository) CreateLocationAlloc(location string) {
	cacheRepository.setLocalStorageLocation(location)
	workLocation := cacheRepository.localStorage.GetLocation(location)
	if workLocation != nil {
		if data := cacheRepository.readLocatinAlloc(location); data != nil {
			cacheRepository.allocStore.CreateAlloc(location, data)
			if cacheRepository.HasAlloc(location) {
				cacheRepository.procLocationAllocFunc(location, workLocation.Server, []*models.Server{})
			}
		}
	}
}
CreateLocationAlloc is exported
package cache
import _ "github.com/cloudtask/cloudtask-center/cache/driver/mongo"
import _ "github.com/cloudtask/cloudtask-center/cache/driver/ngcloud"
import "github.com/cloudtask/cloudtask-center/cache/driver"
import "github.com/cloudtask/cloudtask-center/cache/driver/types"
import "github.com/cloudtask/common/models"
import "github.com/cloudtask/libtools/gounits/httpx"
import "github.com/cloudtask/libtools/gounits/logger"
import "github.com/cloudtask/libtools/gzkwrapper"
import (
	"bytes"
	"encoding/json"
	"net"
	"net/http"
	"strings"
	"time"
)
type ReadLocationAllocFunc func(location string) []byte
type ProcLocationAllocFunc func(location string, addServers []*models.Server, delServers []*models.Server)
type CacheConfigs struct {
	LRUSize                 int
	StorageBackend          types.Backend
	StorageDriverParameters types.Parameters
	AllocHandlerFunc        AllocCacheEventHandlerFunc
	NodeHandlerFunc         NodeCacheEventHandlerFunc
	ReadLocationAllocFunc   ReadLocationAllocFunc
	ProcLocationAllocFunc   ProcLocationAllocFunc
}
type CacheRepository struct {
	nodeStore             *NodeStore
	allocStore            *AllocStore
	localStorage          *LocalStorage
	client                *httpx.HttpClient
	storageDriver         driver.StorageDriver
	readLocationAllocFunc ReadLocationAllocFunc
	procLocationAllocFunc ProcLocationAllocFunc
}
func NewCacheRepository(configs *CacheConfigs) (*CacheRepository, error) {
	storageDriver, err := driver.NewDriver(configs.StorageBackend, configs.StorageDriverParameters)
	if err != nil {
		return nil, err
	}
	if configs.LRUSize <= 0 {
		configs.LRUSize = DefaultLRUSize
	}
	client := httpx.NewClient().
		SetTransport(&http.Transport{
			Proxy: http.ProxyFromEnvironment,
			DialContext: (&net.Dialer{
				Timeout:   30 * time.Second,
				KeepAlive: 60 * time.Second,
			}).DialContext,
			DisableKeepAlives:     false,
			MaxIdleConns:          25,
			MaxIdleConnsPerHost:   25,
			IdleConnTimeout:       90 * time.Second,
			TLSHandshakeTimeout:   http.DefaultTransport.(*http.Transport).TLSHandshakeTimeout,
			ExpectContinueTimeout: http.DefaultTransport.(*http.Transport).ExpectContinueTimeout,
		})
	return &CacheRepository{
		nodeStore:             NewNodeStore(configs.NodeHandlerFunc),
		allocStore:            NewAllocStore(configs.AllocHandlerFunc),
		localStorage:          NewLocalStorage(configs.LRUSize),
		client:                client,
		storageDriver:         storageDriver,
		readLocationAllocFunc: configs.ReadLocationAllocFunc,
		procLocationAllocFunc: configs.ProcLocationAllocFunc,
	}, nil
}
func (cacheRepository *CacheRepository) Open() error {
	return cacheRepository.storageDriver.Open()
}
func (cacheRepository *CacheRepository) Close() {
	cacheRepository.storageDriver.Close()
}
func (cacheRepository *CacheRepository) SetStorageDriverConfigParameters(parameters types.Parameters) {
	cacheRepository.storageDriver.SetConfigParameters(parameters)
}
func (cacheRepository *CacheRepository) Clear() {
	cacheRepository.nodeStore.ClearWorkers()
	cacheRepository.allocStore.ClearAlloc()
	cacheRepository.localStorage.Clear()
}
func (cacheRepository *CacheRepository) setLocalStorageLocation(location string) {
	workLocation := cacheRepository.storageDriver.GetLocation(location)
	if workLocation != nil {
		cacheRepository.localStorage.SetLocation(workLocation)
	}
}
func (cacheRepository *CacheRepository) removeLocalStorageLocation(location string) {
	cacheRepository.localStorage.RemoveLocation(location)
}
func (cacheRepository *CacheRepository) InitLocalStorageLocations() {
	cacheRepository.localStorage.Clear()
	locationsName := cacheRepository.storageDriver.GetLocationsName()
	for _, location := range locationsName {
		if strings.TrimSpace(location) != "" {
			cacheRepository.CreateLocationAlloc(location)
		}
	}
}
func (cacheRepository *CacheRepository) readLocatinAlloc(location string) []byte {
	data := cacheRepository.readLocationAllocFunc(location)
	if data == nil {
		jobsAlloc := &models.JobsAlloc{
			Version: 1,
			Jobs:    make([]*models.JobData, 0),
		}
		buffer := bytes.NewBuffer([]byte{})
		if err := json.NewEncoder(buffer).Encode(jobsAlloc); err != nil {
			return nil
		}
		data = buffer.Bytes()
	}
	return data
}