本文整理汇总了Golang中github.com/youtube/vitess/go/cache.NewLRUCache函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLRUCache函数的具体用法?Golang NewLRUCache怎么用?Golang NewLRUCache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLRUCache函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewThrottler
// NewThrottle creates a new client throttler that blocks spammy clients.
// UPDATED in 2015-01-17: clients now have to specify the limits. Use 10 and
// 1000 if you want to use the old default values.
func NewThrottler(maxPerMinute int, maxHosts int64) *ClientThrottle {
r := ClientThrottle{
maxPerMinute: maxPerMinute,
c: cache.NewLRUCache(maxHosts),
blocked: cache.NewLRUCache(maxHosts),
stop: make(chan bool),
}
go r.cleanup()
return &r
}
开发者ID:nictuku,项目名称:nettools,代码行数:13,代码来源:ratelimit.go
示例2: NewSchemaInfo
func NewSchemaInfo(queryCacheSize int, reloadTime time.Duration, idleTimeout time.Duration, sensitiveMode bool) *SchemaInfo {
si := &SchemaInfo{
queryCacheSize: queryCacheSize,
queries: cache.NewLRUCache(int64(queryCacheSize)),
rules: NewQueryRules(),
connPool: NewConnectionPool("", 2, idleTimeout),
reloadTime: reloadTime,
ticks: timer.NewTimer(reloadTime),
sensitiveMode: sensitiveMode,
}
stats.Publish("QueryCacheLength", stats.IntFunc(si.queries.Length))
stats.Publish("QueryCacheSize", stats.IntFunc(si.queries.Size))
stats.Publish("QueryCacheCapacity", stats.IntFunc(si.queries.Capacity))
stats.Publish("QueryCacheOldest", stats.StringFunc(func() string {
return fmt.Sprintf("%v", si.queries.Oldest())
}))
stats.Publish("SchemaReloadTime", stats.DurationFunc(func() time.Duration {
return si.reloadTime
}))
stats.Publish("TableStats", stats.NewMatrixFunc("Table", "Stats", si.getTableStats))
stats.Publish("TableInvalidations", stats.CountersFunc(si.getTableInvalidations))
stats.Publish("QueryCounts", stats.NewMatrixFunc("Table", "Plan", si.getQueryCount))
stats.Publish("QueryTimesNs", stats.NewMatrixFunc("Table", "Plan", si.getQueryTime))
stats.Publish("QueryRowCounts", stats.NewMatrixFunc("Table", "Plan", si.getQueryRowCount))
stats.Publish("QueryErrorCounts", stats.NewMatrixFunc("Table", "Plan", si.getQueryErrorCount))
// query_plans cannot be shown in sensitive mode
if !si.sensitiveMode {
http.Handle("/debug/query_plans", si)
}
http.Handle("/debug/query_stats", si)
http.Handle("/debug/table_stats", si)
http.Handle("/debug/schema", si)
return si
}
开发者ID:qman1989,项目名称:vitess,代码行数:34,代码来源:schema_info.go
示例3: NewSchemaInfo
// NewSchemaInfo creates a new SchemaInfo.
func NewSchemaInfo(
queryCacheSize int,
statsPrefix string,
endpoints map[string]string,
reloadTime time.Duration,
idleTimeout time.Duration,
enablePublishStats bool,
queryServiceStats *QueryServiceStats) *SchemaInfo {
si := &SchemaInfo{
queries: cache.NewLRUCache(int64(queryCacheSize)),
connPool: NewConnPool("", 2, idleTimeout, enablePublishStats, queryServiceStats),
ticks: timer.NewTimer(reloadTime),
endpoints: endpoints,
reloadTime: reloadTime,
}
if enablePublishStats {
stats.Publish(statsPrefix+"QueryCacheLength", stats.IntFunc(si.queries.Length))
stats.Publish(statsPrefix+"QueryCacheSize", stats.IntFunc(si.queries.Size))
stats.Publish(statsPrefix+"QueryCacheCapacity", stats.IntFunc(si.queries.Capacity))
stats.Publish(statsPrefix+"QueryCacheOldest", stats.StringFunc(func() string {
return fmt.Sprintf("%v", si.queries.Oldest())
}))
stats.Publish(statsPrefix+"SchemaReloadTime", stats.DurationFunc(si.ticks.Interval))
_ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheStats", []string{"Table", "Stats"}, si.getRowcacheStats)
_ = stats.NewMultiCountersFunc(statsPrefix+"RowcacheInvalidations", []string{"Table"}, si.getRowcacheInvalidations)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryCounts", []string{"Table", "Plan"}, si.getQueryCount)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount)
_ = stats.NewMultiCountersFunc(statsPrefix+"QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount)
}
for _, ep := range endpoints {
http.Handle(ep, si)
}
return si
}
开发者ID:fengshao0907,项目名称:vitess,代码行数:36,代码来源:schema_info.go
示例4: NewSchemaInfo
func NewSchemaInfo(queryCacheSize int, reloadTime time.Duration, idleTimeout time.Duration) *SchemaInfo {
si := &SchemaInfo{
queries: cache.NewLRUCache(int64(queryCacheSize)),
rules: NewQueryRules(),
connPool: dbconnpool.NewConnectionPool("", 2, idleTimeout),
ticks: timer.NewTimer(reloadTime),
}
stats.Publish("QueryCacheLength", stats.IntFunc(si.queries.Length))
stats.Publish("QueryCacheSize", stats.IntFunc(si.queries.Size))
stats.Publish("QueryCacheCapacity", stats.IntFunc(si.queries.Capacity))
stats.Publish("QueryCacheOldest", stats.StringFunc(func() string {
return fmt.Sprintf("%v", si.queries.Oldest())
}))
stats.Publish("SchemaReloadTime", stats.DurationFunc(si.ticks.Interval))
_ = stats.NewMultiCountersFunc("TableStats", []string{"Table", "Stats"}, si.getTableStats)
_ = stats.NewMultiCountersFunc("TableInvalidations", []string{"Table"}, si.getTableInvalidations)
_ = stats.NewMultiCountersFunc("QueryCounts", []string{"Table", "Plan"}, si.getQueryCount)
_ = stats.NewMultiCountersFunc("QueryTimesNs", []string{"Table", "Plan"}, si.getQueryTime)
_ = stats.NewMultiCountersFunc("QueryRowCounts", []string{"Table", "Plan"}, si.getQueryRowCount)
_ = stats.NewMultiCountersFunc("QueryErrorCounts", []string{"Table", "Plan"}, si.getQueryErrorCount)
http.Handle("/debug/query_plans", si)
http.Handle("/debug/query_stats", si)
http.Handle("/debug/table_stats", si)
http.Handle("/debug/schema", si)
return si
}
开发者ID:chinna1986,项目名称:vitess,代码行数:26,代码来源:schema_info.go
示例5: TestSet
func TestSet(t *testing.T) {
clientID := "clientID"
duration := time.Hour
lruCache := lru.NewLRUCache(10)
cache := NewLRUCache(clientID, duration, lruCache)
time := time.Unix(1408281677, 0)
url := "http://example.com/fantasy"
expectedContent := createLeagueList(League{LeagueKey: "123"})
cache.Set(url, time, expectedContent)
cacheKey := cache.getKey(url, time)
value, ok := lruCache.Get(cacheKey)
if !ok {
t.Fatal("Content not set in LRU cache correctly")
}
lruCacheValue, ok := value.(*LRUCacheValue)
if !ok {
t.Fatalf("Incorrect type used in LRU cache: %T", value)
}
if lruCacheValue.content != expectedContent {
t.Fatalf("Unepxected content in cache\n\texpected: %+v\n\t"+
"actual: %+v",
expectedContent,
lruCacheValue.content)
}
}
开发者ID:e0,项目名称:goff,代码行数:29,代码来源:fantasy_test.go
示例6: TestGetWithContent
func TestGetWithContent(t *testing.T) {
clientID := "clientID"
duration := time.Hour
lruCache := lru.NewLRUCache(10)
cache := NewLRUCache(clientID, duration, lruCache)
time := time.Unix(1408281677, 0)
url := "http://example.com/fantasy"
cacheKey := cache.getKey(url, time)
expectedContent := createLeagueList(League{LeagueKey: "123"})
lruCache.Set(cacheKey, &LRUCacheValue{content: expectedContent})
content, ok := cache.Get(url, time)
if !ok {
t.Fatal("Cache did not return content")
}
if content != expectedContent {
t.Fatalf("Cache did not return expected content\n\texpected: %+v"+
"\n\tactual: %+v",
expectedContent,
content)
}
}
开发者ID:e0,项目名称:goff,代码行数:25,代码来源:fantasy_test.go
示例7: NewPeerCache
func NewPeerCache(size int64, listLimit int) *PeerCache {
c := &PeerCache{
lru: cache.NewLRUCache(size),
listLimit: listLimit,
}
return c
}
开发者ID:die-net,项目名称:dhtproxy,代码行数:8,代码来源:cache.go
示例8: NewPlanner
func NewPlanner(schema *planbuilder.Schema, cacheSize int) *Planner {
plr := &Planner{
schema: schema,
plans: cache.NewLRUCache(int64(cacheSize)),
}
// TODO(sougou): Uncomment after making Planner testable.
//http.Handle("/debug/query_plans", plr)
//http.Handle("/debug/schema", plr)
return plr
}
开发者ID:littleyang,项目名称:vitess,代码行数:10,代码来源:planner.go
示例9: NewPlanner
// NewPlanner creates a new planner for VTGate.
// It will watch the vschema in the topology until the ctx is closed.
func NewPlanner(ctx context.Context, serv topo.SrvTopoServer, cell string, cacheSize int) *Planner {
plr := &Planner{
serv: serv,
cell: cell,
plans: cache.NewLRUCache(int64(cacheSize)),
}
plr.WatchSrvVSchema(ctx, cell)
plannerOnce.Do(func() {
http.Handle("/debug/query_plans", plr)
http.Handle("/debug/vschema", plr)
})
return plr
}
开发者ID:dumbunny,项目名称:vitess,代码行数:15,代码来源:planner.go
示例10: NewSchemaInfo
func NewSchemaInfo(queryCacheSize int, reloadTime time.Duration, idleTimeout time.Duration) *SchemaInfo {
si := &SchemaInfo{
queryCacheSize: queryCacheSize,
queries: cache.NewLRUCache(uint64(queryCacheSize)),
rules: NewQueryRules(),
connPool: NewConnectionPool(2, idleTimeout),
reloadTime: reloadTime,
ticks: timer.NewTimer(reloadTime),
}
http.Handle("/debug/query_plans", si)
http.Handle("/debug/query_stats", si)
http.Handle("/debug/table_stats", si)
return si
}
开发者ID:Eric-Chen,项目名称:vitess,代码行数:14,代码来源:schema_info.go
示例11: NewEstimator
// NewEstimator initializes an Estimator object with given capacity and EWMA weightingFactor
func NewEstimator(ca int64, wf float64) *Estimator {
if ca < 1 {
log.Infof("Invalid capacity value: %v, falling back to default(%v)", ca, DefaultCapacity)
ca = DefaultCapacity
}
if wf < 0 || wf > 1 {
log.Infof("Invalid weighting factor: %v, falling back to default(%v)", wf, ewma.DefaultWeightingFactor)
wf = ewma.DefaultWeightingFactor
}
return &Estimator{
records: cache.NewLRUCache(ca),
weightingFactor: wf,
}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:15,代码来源:estimator.go
示例12: TestGetNoContent
func TestGetNoContent(t *testing.T) {
clientID := "clientID"
duration := time.Hour
lruCache := lru.NewLRUCache(10)
cache := NewLRUCache(clientID, duration, lruCache)
time := time.Unix(1408281677, 0)
content, ok := cache.Get("http://example.com/fantasy", time)
if ok {
t.Fatalf("Cache returned content when it should not have been cached"+
"content: %+v",
content)
}
}
开发者ID:e0,项目名称:goff,代码行数:15,代码来源:fantasy_test.go
示例13: TestGetContentOfWrongType
func TestGetContentOfWrongType(t *testing.T) {
clientID := "clientID"
duration := time.Hour
lruCache := lru.NewLRUCache(10)
cache := NewLRUCache(clientID, duration, lruCache)
time := time.Unix(1408281677, 0)
url := "http://example.com/fantasy"
cacheKey := cache.getKey(url, time)
lruCache.Set(cacheKey, mockedValue{})
content, ok := cache.Get(url, time)
if ok {
t.Fatalf("Cache returned content when it the wrong type had been cached"+
"content: %+v",
content)
}
}
开发者ID:e0,项目名称:goff,代码行数:19,代码来源:fantasy_test.go
示例14: NewConsolidator
// NewConsolidator creates a new Consolidator
func NewConsolidator() *Consolidator {
return &Consolidator{queries: make(map[string]*Result), consolidations: cache.NewLRUCache(1000)}
}
开发者ID:CowLeo,项目名称:vitess,代码行数:4,代码来源:consolidator.go
示例15: Size
package lookup
import (
"time"
"github.com/youtube/vitess/go/cache"
)
const (
cacheCapacity = 1024 * 1024 // 1MB
cacheTTL = 1 // 1 second
)
var (
resolveCache = cache.NewLRUCache(cacheCapacity)
)
type cacheValue struct {
Value []string
CreatedAt int64
}
func (cv *cacheValue) Size() int {
var size int
for _, s := range cv.Value {
size += len(s)
}
return size
}
func (cv *cacheValue) Expired() bool {
开发者ID:simudream,项目名称:connectable,代码行数:31,代码来源:cache.go
示例16: NewConsolidator
// NewConsolidator creates a new Consolidator
func NewConsolidator() *Consolidator {
co := &Consolidator{queries: make(map[string]*Result), consolidations: cache.NewLRUCache(1000)}
http.Handle("/debug/consolidations", co)
return co
}
开发者ID:chinna1986,项目名称:vitess,代码行数:6,代码来源:consolidator.go
注:本文中的github.com/youtube/vitess/go/cache.NewLRUCache函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论