// New creates new cachestatic middleware
332478
func New(c Config) func(http.Handler) http.Handler {
	if c.Skipper == nil {
		c.Skipper = DefaultConfig.Skipper
	}
	if c.Indexer == nil {
		c.Indexer = DefaultConfig.Indexer
	}
	if c.Invalidator == nil {
		c.Invalidator = DefaultConfig.Invalidator
	}
	if c.SkipHeaders == nil {
		c.SkipHeaders = DefaultConfig.SkipHeaders
	}

	var (
		l     = &sync.RWMutex{}
		cache = make(map[interface{}]*item)
	)

	if c.Invalidator != nil {
		go func() {
			for {
				p := <-c.Invalidator
				l.Lock()
				if _, ok := p.(invalidateAll); ok {
					cache = make(map[interface{}]*item)
				} else {
					delete(cache, p)
				}
				l.Unlock()
			}
		}()
	}

	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if c.Skipper(r) {
				h.ServeHTTP(w, r)
				return
			}

			p := c.Indexer(r)
			l.RLock()
			if ci := cache[p]; ci != nil {
				l.RUnlock()
				wh := w.Header()
				for k, vs := range ci.header {
					if !c.SkipHeaders(k) {
						wh[k] = vs
					}
				}

				// check Last-Modified
				if !ci.modTime.IsZero() {
					if ts := r.Header.Get(header.IfModifiedSince); len(ts) > 0 {
						t, _ := http.ParseTime(ts)
						if ci.modTime.Equal(t) {
							wh.Del(header.ContentType)
							wh.Del(header.ContentLength)
							wh.Del(header.AcceptRanges)
							w.WriteHeader(http.StatusNotModified)
							return
						}
					}
				}

				w.Header().Set("X-Cache", "HIT")
				io.Copy(w, bytes.NewReader(ci.data))
				return
			}
			l.RUnlock()
			w.Header().Set("X-Cache", "MISS")
			cw := &responseWriter{
				ResponseWriter: w,
				cache:          &bytes.Buffer{},
			}
			h.ServeHTTP(cw, r)

			// cache only status ok
			if cw.code == http.StatusOK {
				l.Lock()
				cache[p] = createItem(cw)
				l.Unlock()
			}
		})
	}
}
761855
func (l loader) New(ctx context.Context) (backend.Crypto, error) {
	out.Debug(ctx, "Using Crypto Backend: %s", name)
	return New(ctx, Config{
		Umask: fsutil.Umask(),
		Args:  GPGOpts(),
	})
}
877088
func New(cacheName string) *Cache {
	return &Cache{Settings: config.Config("iron_cache"), Name: cacheName}
}
947291
func New(ctx context.Context, next http.Handler, config config.IPWhiteList, name string) (http.Handler, error) {
	logger := middlewares.GetLogger(ctx, name, typeName)
	logger.Debug("Creating middleware")

	if len(config.SourceRange) == 0 {
		return nil, errors.New("sourceRange is empty, IPWhiteLister not created")
	}

	checker, err := ip.NewChecker(config.SourceRange)
	if err != nil {
		return nil, fmt.Errorf("cannot parse CIDR whitelist %s: %v", config.SourceRange, err)
	}

	strategy, err := config.IPStrategy.Get()
	if err != nil {
		return nil, err
	}

	logger.Debugf("Setting up IPWhiteLister with sourceRange: %s", config.SourceRange)
	return &ipWhiteLister{
		strategy:    strategy,
		whiteLister: checker,
		next:        next,
		name:        name,
	}, nil
}
570756
func New(maxSize, maxAge int64) *LruCache {
	c := &LruCache{
		MaxSize: maxSize,
		MaxAge:  maxAge,
		lru:     list.New(),
		cache:   make(map[string]*list.Element),
	}

	return c
}
411294
func New() *Application {
	app := new(Application)
	app.router = newRouter()
	app.staticRouter = make(map[string][]string)
	app.View = NewView()
	app.Config = NewConfig()
	app.errorHandler = make(map[int]ErrorHandlerFunc)
	app.middlewareChain = NewChain()
	app.DefaultErrorHandler = defaultErrorHandler
	app.pool.New = func() interface{} {
		return new(Context)
	}
	app.handlerChain = app.middlewareChain.Final(app.handler)
	return app
}
1244782
func New(ctx context.Context, next http.Handler, maxConns config.MaxConn, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")

	extractFunc, err := utils.NewExtractor(maxConns.ExtractorFunc)
	if err != nil {
		return nil, fmt.Errorf("error creating connection limit: %v", err)
	}

	handler, err := connlimit.New(next, extractFunc, maxConns.Amount)
	if err != nil {
		return nil, fmt.Errorf("error creating connection limit: %v", err)
	}

	return &maxConnection{handler: handler, name: name}, nil
}
1342016
func New(size int) *Cache {
	c := Cache{
		size: size,
	}
	c.Reset()
	return &c
}
1094532
func New(*Options) *Cache {
	// Initialize the heap. The buffer of 1 is really important because
	// its possible for the expiry loop to trigger the heap to update
	// itself and it'd block forever otherwise.
	h := &expiryHeap{NotifyCh: make(chan struct{}, 1)}
	heap.Init(h)

	c := &Cache{
		types:             make(map[string]typeEntry),
		entries:           make(map[string]cacheEntry),
		entriesExpiryHeap: h,
		stopCh:            make(chan struct{}),
	}

	// Start the expiry watcher
	go c.runExpiryLoop()

	return c
}
119437
func New(rp ringpop.Interface, f ClientFactory, ch *tchannel.Channel) Router {
	r := &router{
		ringpop: rp,
		factory: f,
		channel: ch,

		clientCache: make(map[string]cacheEntry),
	}
	rp.AddListener(r)
	return r
}
436368
func New(ttl time.Duration, stop <-chan struct{}) Cache {
	cache := newSchedulerCache(ttl, cleanAssumedPeriod, stop)
	cache.run()
	return cache
}
795005
func New(ctx context.Context, next http.Handler, config config.ReplacePathRegex, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")

	exp, err := regexp.Compile(strings.TrimSpace(config.Regex))
	if err != nil {
		return nil, fmt.Errorf("error compiling regular expression %s: %s", config.Regex, err)
	}

	return &replacePathRegex{
		regexp:      exp,
		replacement: strings.TrimSpace(config.Replacement),
		next:        next,
		name:        name,
	}, nil
}
655896
func New(ctx context.Context, next http.Handler, config config.StripPrefix, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
	return &stripPrefix{
		prefixes: config.Prefixes,
		next:     next,
		name:     name,
	}, nil
}
759472
func New(ctx context.Context, next http.Handler, config config.Headers, name string) (http.Handler, error) {
	// HeaderMiddleware -> SecureMiddleWare -> next
	logger := middlewares.GetLogger(ctx, name, typeName)
	logger.Debug("Creating middleware")

	hasSecureHeaders := config.HasSecureHeadersDefined()
	hasCustomHeaders := config.HasCustomHeadersDefined()
	hasCorsHeaders := config.HasCorsHeadersDefined()

	if !hasSecureHeaders && !hasCustomHeaders && !hasCorsHeaders {
		return nil, errors.New("headers configuration not valid")
	}

	var handler http.Handler
	nextHandler := next

	if hasSecureHeaders {
		logger.Debug("Setting up secureHeaders from %v", config)
		handler = newSecure(next, config)
		nextHandler = handler
	}

	if hasCustomHeaders || hasCorsHeaders {
		logger.Debug("Setting up customHeaders/Cors from %v", config)
		handler = NewHeader(nextHandler, config)
	}

	return &headers{
		handler: handler,
		name:    name,
	}, nil
}
6130
func New(lsnCfg engine.Listener, router http.Handler, stapler stapler.Stapler,
	connTck conntracker.ConnectionTracker, autoCertCache autocert.Cache, wg *sync.WaitGroup,
) (*T, error) {
	scopedRouter, err := newScopeRouter(lsnCfg.Scope, router)
	if err != nil {
		return nil, err
	}
	return &T{
		lsnCfg: lsnCfg,
		router: router,

		stapler:       stapler,
		connTck:       connTck,
		autoCertCache: autoCertCache,
		serveWg:       wg,
		scopedRouter:  scopedRouter,
		state:         srvStateInit,
	}, nil
}
655299
func New(
	nodeLister corelisters.NodeLister,
	podLister corelisters.PodLister,
	cache internalcache.Cache,
	podQueue internalqueue.SchedulingQueue,
) *CacheDebugger {
	return &CacheDebugger{
		Comparer: CacheComparer{
			NodeLister: nodeLister,
			PodLister:  podLister,
			Cache:      cache,
			PodQueue:   podQueue,
		},
		Dumper: CacheDumper{
			cache:    cache,
			podQueue: podQueue,
		},
	}
}
522637
func New(maxentries int) *Cache {
	return &Cache{
		MaxEntries: maxentries,
		ll:         list.New(),
		cache:      make(map[string]*list.Element),
	}
}