Beispiel #1
0
func NewLRUCache(size int) LRUCache {
	cache := lrucache.New(size)

	return &concurrentLruCacheImp{
		cache: cache,
	}
}
Beispiel #2
0
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())
}
Beispiel #3
0
// 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
}
Beispiel #4
0
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
}