コード例 #1
0
ファイル: lrucache.go プロジェクト: Charlesdong/godropbox
func NewLRUCache(size int) LRUCache {
	cache := lrucache.New(size)

	return &concurrentLruCacheImp{
		cache: cache,
	}
}
コード例 #2
0
ファイル: lrucache.go プロジェクト: Charlesdong/godropbox
func (p *concurrentLruCacheImp) Clear() {
	p.lock.Lock()
	defer p.lock.Unlock()

	// there is no way to clear the cache. So, just create a new one
	p.cache = lrucache.New(p.cache.MaxSize())
}
コード例 #3
0
ファイル: dnscache.go プロジェクト: pombredanne/walker-2
// DNSCachingDial wraps the given dial function with Caching of DNS
// resolutions. When a hostname is found in the cache it will call the provided
// dial with the IP address instead of the hostname, so no DNS lookup need be
// performed. It will also cache DNS failures.
//
func DNSCachingDial(dial func(network, addr string) (net.Conn, error), maxEntries int) func(network, addr string) (net.Conn, error) {
	if dial == nil {
		dial = net.Dial
	}
	c := &dnsCache{
		wrappedDial: dial,
		cache:       lrucache.New(maxEntries),
	}
	return c.dial
}
コード例 #4
0
ファイル: datastore.go プロジェクト: pombredanne/walker-2
func NewCassandraDatastore() (*CassandraDatastore, error) {
	ds := &CassandraDatastore{
		cf: GetCassandraConfig(),
	}
	var err error
	ds.db, err = ds.cf.CreateSession()
	if err != nil {
		return nil, fmt.Errorf("Failed to create cassandra datastore: %v", err)
	}
	ds.addedDomains = lrucache.New(Config.AddedDomainsCacheSize)

	u, err := gocql.RandomUUID()
	if err != nil {
		return ds, err
	}
	ds.crawlerUuid = u

	return ds, nil
}