func NewTunnelManager(domain string) *TunnelManager { return &TunnelManager{ domain: domain, tunnels: make(map[string]*Tunnel), idDomainAffinity: cache.New(cacheDuration, cacheCleanupInterval), ipDomainAffinity: cache.New(cacheDuration, cacheCleanupInterval), } }
func NewGDriveFileSystem(clientId string, clientSecret string) *GDriveFileSystem { u, err := user.Current() tokenFile := u.HomeDir + "/.gdrive_token" if *tokenFileFlag != "" { tokenFile = *tokenFileFlag } config.TokenCache = oauth.CacheFile(tokenFile) config.ClientId = clientId config.ClientSecret = clientSecret transport := &oauth.Transport{ Config: config, Transport: &loggingTransport{http.DefaultTransport}, } obtainToken(transport) client, err := drive.New(transport.Client()) if err != nil { log.Errorf("An error occurred creating Drive client: %v\n", err) panic(-3) } fs := &GDriveFileSystem{ client: client, transport: transport, cache: gocache.New(5*time.Minute, 30*time.Second), } return fs }
// NewMemoryKeyValueStore creates an instance of MemoryKeyValueStore // with given backing. func NewMemoryKeyValueStore(cleanupInterval time.Duration) *MemoryKeyValueStore { cache := gocache.New(gocache.NoExpiration, cleanupInterval) store := &MemoryKeyValueStore{ Cache: cache, cleanupInterval: cleanupInterval, } return store }
func NewMemoryStore(prefix string, cleanupInterval time.Duration) Store { cache := cache.New(cache.NoExpiration, cleanupInterval) return &MemoryStore{ Prefix: prefix, Cache: cache, } }
func NewDatabase(t int) *Database { this := Database{ DBType: t, } if t == DB_MAP { this.dbmap = make(map[string]string) } else if t == DB_PREFTREE { this.dbptree = cache.New(0, 0) } return &this }
// NewEC2EventsInterface ... Creates a new EC2InstanceInterface to consume events from func NewEC2EventsInterface(awsKey, awsSecret, awsRegion, awsEnv string) (EC2EventsInterface, error) { var err error glog.Infof("Creating a new EC2 Instances Interface for events") // step: create a new api for the service service := new(ec2Instances) service.listeners = make(map[EventCh]int, 0) service.hosts = make(map[string]string, 0) service.client, err = NewEC2Interface(awsKey, awsSecret, awsRegion, awsEnv) if err != nil { return nil, err } service.cache = gocache.New(1*time.Hour, 5*time.Minute) // step: attempt to grab an initial state of running instances err = service.bootstrapRunningInstances(3) if err != nil { return nil, fmt.Errorf("failed to bootstrap service, unable to retrieve runnings instance") } // step: start the synchronizing loop go service.synchronize() return service, nil }
func init() { _cache = cacheStr.New(hash.HashJenkins, true, 10*time.Minute, nil) go_cache = gocache.New(5*time.Minute, 10*time.Minute) }
func main() { fd := flag.Uint("fd", 0, "fd to listen and serve") port := flag.Uint("port", 3001, "port to listen and serve") flag.Parse() c := goCache.New(5*time.Minute, 30*time.Second) // まずキャッシュを取る // ここを goroutine にしないことで準備ができるまでファイルディスクリプタをListenしないのでリクエストが来ない cacheFetcher(c) interval := time.Tick(30 * time.Second) go func() { for { <-interval cacheFetcher(c) } }() cs := make(chan os.Signal, 1) ec := make(chan int) signal.Notify(cs, syscall.SIGTERM, syscall.SIGINT) go func() { for { switch <-cs { // circusctl reload は SIGTERM を送る case syscall.SIGTERM: fmt.Println("SIGTERM!!") time.Sleep(20 * time.Second) fmt.Println("SIGTERM!!!") ec <- 0 case syscall.SIGINT: ec <- 0 } } }() go func() { for i := 0; ; i++ { time.Sleep(200 * time.Millisecond) fmt.Printf("%d\n", i) } }() http.HandleFunc("/app_check", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusTeapot) }) var l net.Listener var err error if *fd == 0 { log.Println(fmt.Sprintf("listening on port %d", *port)) l, err = net.ListenTCP("tcp", &net.TCPAddr{Port: int(*port)}) } else { log.Println("listening on socket") l, err = net.FileListener(os.NewFile(uintptr(*fd), "")) } if err != nil { log.Fatal(err) panic(err) } go func() { log.Println(http.Serve(l, nil)) }() <-ec }
// NewMemoryStoreWithOptions creates a new instance of memory store with options. func NewMemoryStoreWithOptions(options StoreOptions) Store { return &MemoryStore{ Prefix: options.Prefix, Cache: cache.New(cache.NoExpiration, options.CleanUpInterval), } }
// Creates a new GoCache with the given intervals // defaultExpiration = 0 is never expire // cleanupInterval = 0 is never attempt to clean up expired func New(defaultExpirationSeconds, cleanupIntervalSeconds int) *GoCache { return &GoCache{ Cache: cache.New(time.Duration(defaultExpirationSeconds)*time.Second, time.Duration(cleanupIntervalSeconds)*time.Second), } }
// FlushDB clears all keys func (store *MemoryKeyValueStore) FlushDB() error { store.Cache = gocache.New(gocache.NoExpiration, store.cleanupInterval) return nil }
func NewDirEntryCache(ttl time.Duration) DirEntryCache { return &realDirEntryCache{ cache: cache.New(ttl, CachePurgeInterval), eventLog: trace.NewEventLog("DirEntryCache", ""), } }
func NewInmemCache() Cacher { return inmemCache{ ram: goc.New(60*time.Minute, 1*time.Minute), } }
html *gq.Selection } type Error struct { Msg string } func (e *Error) Error() string { return e.Msg } var debug bool var num_procs = runtime.NumCPU() var dbmap *gorp.DbMap var cache = gocache.New(5*time.Hour, 30*time.Second) var wordCounts = gocache.New(5*time.Hour, 30*time.Second) var verseWg sync.WaitGroup var rawVerseWg sync.WaitGroup var chapterWg sync.WaitGroup var chaptersIn = make(chan Chapter) var chaptersOut = make(chan Verse) var versesIn = make(chan Verse) var versesOut = make(chan Verse) var rawVersesIn = make(chan Verse) var rawVersesOut = make(chan Verse) var numRawVerseWorkers = num_procs var numVerseWorkers = num_procs
func init() { _cache = cacheUint.New(true, 10*time.Minute, nil) go_cache = gocache.New(5*time.Minute, 10*time.Minute) }
"syscall" "time" goCache "github.com/pmylund/go-cache" "github.com/gorilla/context" "github.com/gorilla/mux" "github.com/gorilla/sessions" _ "github.com/lib/pq" "github.com/walf443/stopwatch" ) var ( db *sql.DB store *sessions.CookieStore exCache = goCache.New(10*time.Second, 5*time.Second) tenkiCache = goCache.New(1*time.Second, 1*time.Second) userCache = goCache.New(120*time.Second, 30*time.Second) ) var kenCache map[string]Data var ken2Cache map[string]Data var surnameCache map[string]Data var givennameCache map[string]Data type User struct { ID int Email string Grade string }