本文整理匯總了Golang中github.com/hashicorp/golang-lru.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newQuotaEvaluator
// newQuotaEvaluator configures an admission controller that can enforce quota constraints
// using the provided registry. The registry must have the capability to handle group/kinds that
// are persisted by the server this admission controller is intercepting
func newQuotaEvaluator(client clientset.Interface, registry quota.Registry) (*quotaEvaluator, error) {
liveLookupCache, err := lru.New(100)
if err != nil {
return nil, err
}
updatedCache, err := lru.New(100)
if err != nil {
return nil, err
}
lw := &cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
return client.Core().ResourceQuotas(api.NamespaceAll).List(options)
},
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
return client.Core().ResourceQuotas(api.NamespaceAll).Watch(options)
},
}
indexer, reflector := cache.NewNamespaceKeyedIndexerAndReflector(lw, &api.ResourceQuota{}, 0)
reflector.Run()
return "aEvaluator{
client: client,
indexer: indexer,
registry: registry,
liveLookupCache: liveLookupCache,
liveTTL: time.Duration(30 * time.Second),
updatedQuotas: updatedCache,
queue: workqueue.New(),
work: map[string][]*admissionWaiter{},
dirtyWork: map[string][]*admissionWaiter{},
inProgress: sets.String{},
}, nil
}
示例2: newQuotaAccessor
// newQuotaAccessor creates an object that conforms to the QuotaAccessor interface to be used to retrieve quota objects.
func newQuotaAccessor(client clientset.Interface) (*quotaAccessor, error) {
liveLookupCache, err := lru.New(100)
if err != nil {
return nil, err
}
updatedCache, err := lru.New(100)
if err != nil {
return nil, err
}
lw := &cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
internalOptions := api.ListOptions{}
v1.Convert_v1_ListOptions_To_api_ListOptions(&options, &internalOptions, nil)
return client.Core().ResourceQuotas(api.NamespaceAll).List(internalOptions)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
internalOptions := api.ListOptions{}
v1.Convert_v1_ListOptions_To_api_ListOptions(&options, &internalOptions, nil)
return client.Core().ResourceQuotas(api.NamespaceAll).Watch(internalOptions)
},
}
indexer, reflector := cache.NewNamespaceKeyedIndexerAndReflector(lw, &api.ResourceQuota{}, 0)
return "aAccessor{
client: client,
indexer: indexer,
reflector: reflector,
liveLookupCache: liveLookupCache,
liveTTL: time.Duration(30 * time.Second),
updatedQuotas: updatedCache,
}, nil
}
示例3: main
func main() {
parse_flags()
var err error
if enable_cache {
// create cache
dns_cache, err = lru.New(1000)
if err != nil {
log.Fatal(err)
}
}
dns.HandleFunc(".", handleRoot)
logger = NewLogger(logfile, debug)
logger.Info("Listen on %s\n", bind_addr)
go func() {
/* listen tcp */
err := dns.ListenAndServe(bind_addr, "tcp", nil)
if err != nil {
log.Fatal(err)
}
}()
/* listen udp */
err = dns.ListenAndServe(bind_addr, "udp", nil)
if err != nil {
log.Fatal(err)
}
}
示例4: NewKeyCacheStandard
// NewKeyCacheStandard constructs a new KeyCacheStandard with the given
// cache capacity.
func NewKeyCacheStandard(capacity int) *KeyCacheStandard {
head, err := lru.New(capacity)
if err != nil {
panic(err.Error())
}
return &KeyCacheStandard{head}
}
示例5: NewLimitRanger
// NewLimitRanger returns an object that enforces limits based on the supplied limit function
func NewLimitRanger(client clientset.Interface, actions LimitRangerActions) (admission.Interface, error) {
liveLookupCache, err := lru.New(10000)
if err != nil {
return nil, err
}
lw := &cache.ListWatch{
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
return client.Core().LimitRanges(api.NamespaceAll).List(options)
},
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
return client.Core().LimitRanges(api.NamespaceAll).Watch(options)
},
}
indexer, reflector := cache.NewNamespaceKeyedIndexerAndReflector(lw, &api.LimitRange{}, 0)
reflector.Run()
if actions == nil {
actions = &DefaultLimitRangerActions{}
}
return &limitRanger{
Handler: admission.NewHandler(admission.Create, admission.Update),
client: client,
actions: actions,
indexer: indexer,
liveLookupCache: liveLookupCache,
liveTTL: time.Duration(30 * time.Second),
}, nil
}
示例6: NewPointInPolygon
func NewPointInPolygon(source string, cache_size int, cache_trigger int, logger *log.WOFLogger) (*WOFPointInPolygon, error) {
rtree := rtreego.NewTree(2, 25, 50)
cache, err := lru.New(cache_size)
if err != nil {
return nil, err
}
metrics := NewPointInPolygonMetrics()
placetypes := make(map[string]int)
pip := WOFPointInPolygon{
Rtree: rtree,
Source: source,
Cache: cache,
CacheSize: cache_size,
CacheTrigger: cache_trigger,
Placetypes: placetypes,
Metrics: metrics,
Logger: logger,
}
return &pip, nil
}
示例7: NewMDCacheStandard
// NewMDCacheStandard constructs a new MDCacheStandard using the given
// cache capacity.
func NewMDCacheStandard(capacity int) *MDCacheStandard {
tmp, err := lru.New(capacity)
if err != nil {
return nil
}
return &MDCacheStandard{tmp}
}
示例8: NewDatastore
// NewDatastore constructs a new LRU Datastore with given capacity.
func NewDatastore(capacity int) (*Datastore, error) {
cache, err := lru.New(capacity)
if err != nil {
return nil, err
}
return &Datastore{cache: cache}, nil
}
示例9: newFlowCache
func newFlowCache() *flowCache {
c, err := lru.New(8192)
if err != nil {
panic(fmt.Sprintf("LRU flow cache: %v", err))
}
return &flowCache{
cache: c,
}
}
示例10: NewCache
func NewCache(limit int, ttl time.Duration) *Cache {
var cache *lru.Cache
if 0 < limit {
var err error
cache, err = lru.New(limit)
if err != nil {
panic(err)
}
}
return &Cache{cache: cache, TTL: ttl}
}
示例11: NewStatusAdmitter
// NewStatusAdmitter creates a plugin wrapper that ensures every accepted
// route has a status field set that matches this router. The admitter manages
// an LRU of recently seen conflicting updates to handle when two router processes
// with differing configurations are writing updates at the same time.
func NewStatusAdmitter(plugin router.Plugin, client client.RoutesNamespacer, name string) *StatusAdmitter {
expected, _ := lru.New(1024)
return &StatusAdmitter{
plugin: plugin,
client: client,
routerName: name,
contentionInterval: 1 * time.Minute,
expected: expected,
}
}
示例12: NewLifecycle
// NewLifecycle creates a new namespace lifecycle admission control handler
func NewLifecycle(c clientset.Interface, immortalNamespaces sets.String) (admission.Interface, error) {
forceLiveLookupCache, err := lru.New(100)
if err != nil {
panic(err)
}
return &lifecycle{
Handler: admission.NewHandler(admission.Create, admission.Update, admission.Delete),
client: c,
immortalNamespaces: immortalNamespaces,
forceLiveLookupCache: forceLiveLookupCache,
}, nil
}
示例13: setup
func (pc *ProofCache) setup() error {
pc.Lock()
defer pc.Unlock()
if pc.lru != nil {
return nil
}
lru, err := lru.New(pc.capac)
if err != nil {
return err
}
pc.lru = lru
return nil
}
示例14: Put
func (cs lrustore) Put(key string, value interface{}) {
prefix, key := key[:PREFIX_LEN], key[PREFIX_LEN:]
mp, ok := cs[prefix]
if !ok {
var err error
mp, err = lru.New(10000)
if err != nil {
return
}
cs[prefix] = mp
}
mp.Add(key, value)
}
示例15: NewEtcdMutationCache
// NewEtcdMutationCache gives back a MutationCache that understands how to deal with etcd backed objects
func NewEtcdMutationCache(backingCache cache.Store) MutationCache {
lru, err := lru.New(100)
if err != nil {
// errors only happen on invalid sizes, this would be programmer error
panic(err)
}
return &mutationCache{
backingCache: backingCache,
mutationCache: lru,
comparator: etcd.APIObjectVersioner{},
}
}