當前位置: 首頁>>代碼示例>>Golang>>正文


Golang lrucache.NewMultiLRUCache函數代碼示例

本文整理匯總了Golang中github.com/cloudflare/golibs/lrucache.NewMultiLRUCache函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewMultiLRUCache函數的具體用法?Golang NewMultiLRUCache怎麽用?Golang NewMultiLRUCache使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewMultiLRUCache函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewFilter

func NewFilter(config *Config) (_ filters.Filter, err error) {
	onceCA.Do(func() {
		defaultCA, err = NewRootCA(config.RootCA.Name,
			time.Duration(config.RootCA.Duration)*time.Second,
			config.RootCA.RsaBits,
			config.RootCA.Dirname,
			config.RootCA.Portable)
		if err != nil {
			glog.Fatalf("NewRootCA(%#v) error: %v", config.RootCA.Name, err)
		}
	})

	f := &Filter{
		Config:         *config,
		CA:             defaultCA,
		CAExpiry:       time.Duration(config.RootCA.Duration) * time.Second,
		TLSConfigCache: lrucache.NewMultiLRUCache(4, 4096),
		Ports:          make(map[string]struct{}),
		Sites:          helpers.NewHostMatcher(config.Sites),
	}

	for _, port := range config.Ports {
		f.Ports[strconv.Itoa(port)] = struct{}{}
	}

	return f, nil
}
開發者ID:taiping-z,項目名稱:goproxy,代碼行數:27,代碼來源:stripssl.go

示例2: NewFilter

func NewFilter(config *Config) (_ filters.Filter, err error) {
	var ca *RootCA

	ca, err = NewRootCA(config.RootCA.Name, time.Duration(config.RootCA.Duration)*time.Second, config.RootCA.RsaBits, config.RootCA.Dirname)
	if err != nil {
		return nil, err
	}

	if _, err := os.Stat(config.RootCA.Dirname); os.IsNotExist(err) {
		if err = os.Mkdir(config.RootCA.Dirname, 0755); err != nil {
			return nil, err
		}
	}

	f := &Filter{
		CA:         ca,
		CAExpires:  time.Duration(config.RootCA.Duration) * time.Second,
		CACache:    lrucache.NewMultiLRUCache(4, 4096),
		SiteLists1: make(map[string]struct{}),
		SiteLists2: make([]string, 0),
	}

	for _, site := range config.Sites {
		if !strings.Contains(site, "*") {
			f.SiteLists1[site] = struct{}{}
		} else {
			f.SiteLists2 = append(f.SiteLists2, site)
		}
	}

	return f, nil
}
開發者ID:uuudbx,項目名稱:goproxy,代碼行數:32,代碼來源:stripssl.go

示例3: NewIplist

func NewIplist(lists map[string][]string, blacklist []string, dualStack bool) (*Iplist, error) {
	iplist := &Iplist{
		lists:     lists,
		blacklist: httpproxy.NewHostMatcher(blacklist),
		dnsCache:  lrucache.NewMultiLRUCache(4, 10240),
		dualStack: dualStack,
	}

	return iplist, nil
}
開發者ID:uuudbx,項目名稱:goproxy,代碼行數:10,代碼來源:dialer.go

示例4: NewFilter

func NewFilter(config *Config) (filters.Filter, error) {
	f := &Filter{
		ByPassHeaders: lrucache.NewMultiLRUCache(4, uint(config.CacheSize)),
		Basic:         make(map[string]string),
		WhiteList:     make(map[string]struct{}),
	}

	for _, v := range config.Basic {
		f.Basic[v.Username] = v.Password
	}

	for _, v := range config.WhiteList {
		f.WhiteList[v] = struct{}{}
	}

	return f, nil
}
開發者ID:sunjiahz,項目名稱:goproxy,代碼行數:17,代碼來源:auth.go

示例5: NewFilter

func NewFilter(config *Config) (filters.Filter, error) {
	d := &Dailer{}
	d.Timeout = time.Duration(config.Dialer.Timeout) * time.Second
	d.KeepAlive = time.Duration(config.Dialer.KeepAlive) * time.Second
	d.DNSCache = lrucache.NewMultiLRUCache(4, uint(config.DNSCache.Size))
	d.DNSCacheExpires = time.Duration(config.DNSCache.Expires) * time.Second
	d.Blacklist = make(map[string]struct{})

	// d.Blacklist["127.0.0.1"] = struct{}{}
	d.Blacklist["::1"] = struct{}{}
	if addrs, err := net.InterfaceAddrs(); err == nil {
		for _, addr := range addrs {
			switch addr.Network() {
			case "ip":
				d.Blacklist[addr.String()] = struct{}{}
			}
		}
	}
	// glog.V(2).Infof("add blacklist=%v to direct filter", d.Blacklist)

	return &Filter{
		transport: &http.Transport{
			Dial: d.Dial,
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: false,
				ClientSessionCache: tls.NewLRUClientSessionCache(1000),
			},
			TLSHandshakeTimeout: time.Duration(config.Transport.TLSHandshakeTimeout) * time.Second,
			MaxIdleConnsPerHost: config.Transport.MaxIdleConnsPerHost,
			DisableCompression:  config.Transport.DisableCompression,
		},
		ratelimt: RateLimit{
			Threshold: int64(config.RateLimit.Threshold),
			Capacity:  int64(config.RateLimit.Capacity),
			Rate:      float64(config.RateLimit.Rate),
		},
	}, nil
}
開發者ID:zhuyin319,項目名稱:goproxy,代碼行數:38,代碼來源:direct.go

示例6: NewFilter

func NewFilter(config *Config) (filters.Filter, error) {
	d := &Dialer{}
	d.Timeout = time.Duration(config.Dialer.Timeout) * time.Second
	d.KeepAlive = time.Duration(config.Dialer.KeepAlive) * time.Second
	d.Blacklist = make(map[string]struct{})

	d.Window = config.Dialer.Window

	d.Blacklist["127.0.0.1"] = struct{}{}
	d.Blacklist["::1"] = struct{}{}
	if addrs, err := net.InterfaceAddrs(); err == nil {
		for _, addr := range addrs {
			switch addr.Network() {
			case "ip":
				d.Blacklist[addr.String()] = struct{}{}
			}
		}
	}

	var err error

	d.hosts = httpproxy.NewHostMatcherWithString(config.Hosts)

	d.iplist, err = NewIplist(config.Iplist, config.DNS.Servers, config.DNS.Blacklist, d.DualStack)
	if err != nil {
		return nil, err
	}

	d.TLSConfig = &tls.Config{
		InsecureSkipVerify: true,
		ClientSessionCache: tls.NewLRUClientSessionCache(1000),
	}

	d.connTCPDuration = lrucache.NewMultiLRUCache(4, 4096)
	d.connTLSDuration = lrucache.NewMultiLRUCache(4, 4096)
	d.connExpireDuration = 5 * time.Minute

	for _, name := range config.DNS.Expand {
		if _, ok := config.Iplist[name]; ok {
			go func(name string) {
				t := time.Tick(3 * time.Minute)
				for {
					select {
					case <-t:
						d.iplist.ExpandList(name)
					}
				}
			}(name)
		}
	}

	return &Filter{
		transport: &http.Transport{
			Dial:                d.Dial,
			DialTLS:             d.DialTLS,
			DisableKeepAlives:   config.Transport.DisableKeepAlives,
			DisableCompression:  config.Transport.DisableCompression,
			TLSHandshakeTimeout: time.Duration(config.Transport.TLSHandshakeTimeout) * time.Second,
			MaxIdleConnsPerHost: config.Transport.MaxIdleConnsPerHost,
		},
		dialer: d,
	}, nil
}
開發者ID:sunjiahz,項目名稱:goproxy,代碼行數:63,代碼來源:iplist.go

示例7: makeMultiLRU

func makeMultiLRU(capacity uint64) lrucache.Cache {
	shards := uint(2)
	return lrucache.NewMultiLRUCache(shards, uint(capacity)/shards)
}
開發者ID:wheelcomplex,項目名稱:golibs,代碼行數:4,代碼來源:mcache.go

示例8: New

// New returns a new Cache using the provided memcache server(s) with equal
// weight. If a server is listed multiple times, it gets a proportional amount
// of weight.
func New(capacity uint) *Cache {
	return &Cache{
		cache: lrucache.NewMultiLRUCache(4, capacity),
	}
}
開發者ID:chinanjjohn2012,項目名稱:httpcache,代碼行數:8,代碼來源:lrucache.go


注:本文中的github.com/cloudflare/golibs/lrucache.NewMultiLRUCache函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。