Example #1
0
func newServerRedis(srv imageserver.Server) imageserver.Server {
	if flagRedis == "" {
		return srv
	}
	pool := &redis.Pool{
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", flagRedis)
		},
		MaxIdle: 50,
	}
	var cch imageserver_cache.Cache
	cch = &imageserver_cache_redis.Cache{
		Pool:   pool,
		Expire: 7 * 24 * time.Hour,
	}
	cch = &imageserver_cache.IgnoreError{Cache: cch}
	cch = &imageserver_cache.Async{Cache: cch}
	var kg imageserver_cache.KeyGenerator
	kg = imageserver_cache.NewParamsHashKeyGenerator(sha256.New)
	kg = &imageserver_cache.PrefixKeyGenerator{
		KeyGenerator: kg,
		Prefix:       "image:",
	}
	return &imageserver_cache.Server{
		Server:       srv,
		Cache:        cch,
		KeyGenerator: kg,
	}
}
Example #2
0
func newServerCacheMemory(srv imageserver.Server) imageserver.Server {
	if flagCacheMemory <= 0 {
		return srv
	}
	return &imageserver_cache.Server{
		Server:       srv,
		Cache:        imageserver_cache_memory.New(flagCacheMemory),
		KeyGenerator: imageserver_cache.NewParamsHashKeyGenerator(sha256.New),
	}
}
Example #3
0
func newServerGroupcache(srv imageserver.Server) imageserver.Server {
	if flagGroupcache <= 0 {
		return srv
	}
	return imageserver_cache_groupcache.NewServer(
		srv,
		imageserver_cache.NewParamsHashKeyGenerator(sha256.New),
		groupcacheName,
		flagGroupcache,
	)
}
Example #4
0
func newServerMemory(srv imageserver.Server) imageserver.Server {
	if flagMemory <= 0 {
		return srv
	}
	cch := imageserver_cache_memory.New(flagMemory)
	kg := imageserver_cache.NewParamsHashKeyGenerator(sha256.New)
	return &imageserver_cache.Server{
		Server:       srv,
		Cache:        cch,
		KeyGenerator: kg,
	}
}
Example #5
0
func newServerMemcache(srv imageserver.Server) imageserver.Server {
	if flagMemcache == "" {
		return srv
	}
	cl := memcache.New(flagMemcache)
	var cch imageserver_cache.Cache
	cch = &imageserver_cache_memcache.Cache{Client: cl}
	cch = &imageserver_cache.IgnoreError{Cache: cch}
	cch = &imageserver_cache.Async{Cache: cch}
	kg := imageserver_cache.NewParamsHashKeyGenerator(sha256.New)
	return &imageserver_cache.Server{
		Server:       srv,
		Cache:        cch,
		KeyGenerator: kg,
	}
}