コード例 #1
0
ファイル: mongoProvider.go プロジェクト: gtfierro/giles2
func newMongoStore(c *mongoConfig) *mongoStore {
	var err error
	m := &mongoStore{}
	log.Noticef("Connecting to MongoDB at %v...", c.address.String())
	m.session, err = mgo.Dial(c.address.String())
	if err != nil {
		log.Criticalf("Could not connect to MongoDB: %v", err)
		return nil
	}
	log.Notice("...connected!")
	// fetch/create collections and db reference
	m.db = m.session.DB("archiver")
	m.metadata = m.db.C("metadata")

	// add indexes. This will fail Fatal
	m.addIndexes()

	m.pool = newMongoConnectionPool(m.session, m.metadata, 20)

	// configure the unitoftime cache
	m.uotCache = ccache.New(ccache.Configure().MaxSize(1000).ItemsToPrune(50))
	m.uomCache = ccache.New(ccache.Configure().MaxSize(1000).ItemsToPrune(50))
	m.stCache = ccache.New(ccache.Configure().MaxSize(1000).ItemsToPrune(50))
	m.uuidCache = ccache.New(ccache.Configure().MaxSize(1000).ItemsToPrune(50))
	m.cacheExpiry = 10 * time.Minute
	return m
}
コード例 #2
0
ファイル: handler.go プロジェクト: zalando/planb-tokeninfo
// NewTokenInfoProxyHandler returns an http.Handler that proxies every Request to the server
// at the upstreamURL
func NewTokenInfoProxyHandler(upstreamURL *url.URL, cacheMaxSize int64, cacheTTL time.Duration) http.Handler {
	log.Printf("Upstream tokeninfo is %s with %v cache (%d max size)", upstreamURL, cacheTTL, cacheMaxSize)
	p := httputil.NewSingleHostReverseProxy(upstreamURL)
	p.Director = hostModifier(upstreamURL, p.Director)
	cache := ccache.New(ccache.Configure().MaxSize(cacheMaxSize))
	return &tokenInfoProxyHandler{upstream: p, cache: cache, cacheTTL: cacheTTL}
}
コード例 #3
0
ファイル: gerb.go プロジェクト: ChaosCloud/gerb
package gerb

import (
	"crypto/sha1"
	"fmt"
	"github.com/karlseguin/bytepool"
	"github.com/karlseguin/ccache"
	"github.com/karlseguin/gerb/core"
	"io"
	"io/ioutil"
	"time"
)

var Cache = ccache.New(ccache.Configure().MaxItems(1024 * 1024 * 10))

// a chain of templates to render from inner-most to outer-most
type TemplateChain []core.Executable

func (t TemplateChain) Render(writer io.Writer, data map[string]interface{}) {
	if data == nil {
		data = make(map[string]interface{})
	}
	defaultContent := core.BytePool.Checkout()
	context := &core.Context{
		Writer:   defaultContent,
		Data:     data,
		Counters: make(map[string]int),
		Contents: map[string]*bytepool.Item{"$": defaultContent},
	}
	defer cleanup(context)
	lastIndex := len(t) - 1