// NewDiskCache returns a DiskCache, initialized to store its data under the
// given directory.
971108
func NewDiskCache(baseDir string) (*DiskCache, error) {
	err := os.MkdirAll(baseDir, 0700)
	if err != nil {
		return nil, err
	}
	return &DiskCache{baseDir: baseDir, fileList: make(map[string]int)}, nil
}
672550
func NewObjectCache(listObject listObjectFunc, watchObject watchObjectFunc, newObject newObjectFunc, groupResource schema.GroupResource) Store {
	return &objectCache{
		listObject:    listObject,
		watchObject:   watchObject,
		newObject:     newObject,
		groupResource: groupResource,
		items:         make(map[objectKey]*objectCacheItem),
	}
}
960351
func NewCacher(name string, opt Options) (Cache, error) {
	adapter, ok := adapters[name]
	if !ok {
		return nil, fmt.Errorf("cache: unknown adapter '%s'(forgot to import?)", name)
	}
	return adapter, adapter.StartAndGC(opt)
}
350727
func NewInstanceCache(fs fs.FileSystem) *InstanceCache {
	return &InstanceCache{
		fs:      fs,
		maxSize: instanceCacheMaxSize,
		maxAge:  instanceCacheMaxAge,
	}
}
417397
func NewCachingFetcher(cache blobserver.Cache, fetcher blob.Fetcher) *CachingFetcher {
	return &CachingFetcher{c: cache, sf: fetcher}
}
1108476
func NewMemoryCache(memoryLimit int, objectLimit int) *MemoryCache {
	return &MemoryCache{memoryLimit: memoryLimit,
		objectLimit: objectLimit,
		object:      make(map[string]Object)}
}
1317110
func NewCache(capacity uint64) *Cache {
	return &Cache{
		capacity: capacity,
		ll:       list.New(),
		cache:    make(elementMap),
	}
}
160550
func NewCache(backend Reader, options ...CacheOption) *Cache {
	cache := &Cache{
		backend:  backend,
		accounts: make(map[crypto.Address]*accountInfo),
	}
	for _, option := range options {
		option(cache)
	}
	return cache
}
373508
func (f *clusterCacheFactoryImpl) NewClusterCache(ctx context.Context, options ...rest.HTTPClientOption) cluster.ClusterCache {
	return clusterservice.NewCache(f.config, options...)
}
496663
func New(path string) (*Cache, error) {
	cache := &Cache{}

	var err error
	cache.db, err = leveldb.OpenFile(path, nil)

	if err != nil {
		return nil, err
	}
	return cache, nil
}
522637
func New(maxentries int) *Cache {
	return &Cache{
		MaxEntries: maxentries,
		ll:         list.New(),
		cache:      make(map[string]*list.Element),
	}
}
859973
func NewRepoCache(dir string) *RepoCache {
	return &RepoCache{
		baseDir: dir,
		repos:   make(map[string]*git.Repository),
	}
}
857307
func NewObjectStorage(dir *dotgit.DotGit, objectCache cache.Object) *ObjectStorage {
	return NewObjectStorageWithOptions(dir, objectCache, Options{})
}
1312907
func NewCCache() *CCache {
	if maxSize == 0 {
		return nil
	}

	cc := &CCache{
		metricCache:   make(map[schema.AMKey]*CCacheMetric),
		metricRawKeys: make(map[schema.MKey]map[schema.Archive]struct{}),
		accnt:         accnt.NewFlatAccnt(maxSize),
		stop:          make(chan interface{}),
		tracer:        opentracing.NoopTracer{},
	}
	go cc.evictLoop()
	return cc
}
596634
func New(file string, cache int, handles int, namespace string) (*Database, error) {
	// Ensure we have some minimal caching and file guarantees
	if cache < minCache {
		cache = minCache
	}
	if handles < minHandles {
		handles = minHandles
	}
	logger := log.New("database", file)
	logger.Info("Allocated cache and file handles", "cache", common.StorageSize(cache*1024*1024), "handles", handles)

	// Open the db and recover any potential corruptions
	db, err := leveldb.OpenFile(file, &opt.Options{
		OpenFilesCacheCapacity: handles,
		BlockCacheCapacity:     cache / 2 * opt.MiB,
		WriteBuffer:            cache / 4 * opt.MiB, // Two of these are used internally
		Filter:                 filter.NewBloomFilter(10),
	})
	if _, corrupted := err.(*errors.ErrCorrupted); corrupted {
		db, err = leveldb.RecoverFile(file, nil)
	}
	if err != nil {
		return nil, err
	}
	// Assemble the wrapper with all the registered metrics
	ldb := &Database{
		fn:       file,
		db:       db,
		log:      logger,
		quitChan: make(chan chan error),
	}
	ldb.compTimeMeter = metrics.NewRegisteredMeter(namespace+"compact/time", nil)
	ldb.compReadMeter = metrics.NewRegisteredMeter(namespace+"compact/input", nil)
	ldb.compWriteMeter = metrics.NewRegisteredMeter(namespace+"compact/output", nil)
	ldb.diskReadMeter = metrics.NewRegisteredMeter(namespace+"disk/read", nil)
	ldb.diskWriteMeter = metrics.NewRegisteredMeter(namespace+"disk/write", nil)
	ldb.writeDelayMeter = metrics.NewRegisteredMeter(namespace+"compact/writedelay/duration", nil)
	ldb.writeDelayNMeter = metrics.NewRegisteredMeter(namespace+"compact/writedelay/counter", nil)

	// Start up the metrics gathering and return
	go ldb.meter(metricsGatheringInterval)
	return ldb, nil
}
765609
func NewCache(c Coser) Coser {
	return &cache{
		Coser:     c,
		cache:     make(map[string]float32),
		errCache:  make(map[string]error),
		cosnCache: make(map[string][]Match),
	}
}
1247509
func NewCacheOnStorage(
	cache Storage,
	storage Storage) Storage {

	return &CacheOnStorage{
		cache:   cache,
		storage: storage,
	}
}