当前位置: 首页>>代码示例>>Golang>>正文


Golang cache.New函数代码示例

本文整理汇总了Golang中tools/cache.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestConnectionsItems

func TestConnectionsItems(t *testing.T) {
	stats := New(42, "9999", "8888", 1024, 2, true, true)
	storage := cache.New(42)
	if len(stats.Items(storage)) != 6 {
		t.Fatalf("Unexpected length of returned value; expected 6.")
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:7,代码来源:stat_test.go

示例2: TestSerializationCase1

func TestSerializationCase1(t *testing.T) {
	stats := New(42, "9999", "8888", 1024, 2, true, true)
	storage := cache.New(42)
	if len(stats.Serialize(storage)) != 19 {
		t.Fatalf("Unexpected number of fields of returned value: ", stats)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:7,代码来源:stat_test.go

示例3: TestSettingsSerialization

func TestSettingsSerialization(t *testing.T) {
	stats := New(42, "9999", "8888", 1024, 2, true, true)
	storage := cache.New(42)
	res := stats.Settings(storage)
	if len(res) != 12 {
		t.Fatalf("Unexpected length of Settings serialization: %d, expected 12;", len(res), res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:8,代码来源:stat_test.go

示例4: TestHandlingSuiteSet2

func TestHandlingSuiteSet2(t *testing.T) {
	var storage = cache.New(4)
	var testEnum = Ascii_protocol_enum{"set", []string{"key"}, 1, 0, 42, 0, false, make([]byte, 42), ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err == nil || string(res) != strings.Replace(SERVER_ERROR_TEMP, "%s", "Not enough memory", 1) {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:8,代码来源:protocol_test.go

示例5: TestHandlingSuiteFlushAll

func TestHandlingSuiteFlushAll(t *testing.T) {
	var storage = cache.New(42)
	var testEnum = Ascii_protocol_enum{"flush_all", nil, 0, 0, 0, 0, false, nil, ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != "OK\r\n" {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:8,代码来源:protocol_test.go

示例6: TestHandlingSuiteSet1

func TestHandlingSuiteSet1(t *testing.T) {
	var storage = cache.New(42)
	var testEnum = Ascii_protocol_enum{"set", []string{"key"}, 1, 0, 4, 0, false, []byte("TEST"), ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != "STORED\r\n" {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:8,代码来源:protocol_test.go

示例7: TestHandlingStatistic

func TestHandlingStatistic(t *testing.T) {
	var testEnum = Ascii_protocol_enum{"stats", nil, 0, 0, 0, 0, false, nil, ""}
	var stats = stat.New(42, "9999", "8888", 1024, 2, true, true)
	var storage = cache.New(42)

	res, err := testEnum.HandleRequest(storage, stats)
	if err != nil || res == nil {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:10,代码来源:protocol_test.go

示例8: TestHandlingSuiteDelete2

func TestHandlingSuiteDelete2(t *testing.T) {
	var storage = cache.New(42)
	var testEnum = Ascii_protocol_enum{"set", []string{"key"}, 1, 0, 4, 0, false, []byte("TEST"), ""}
	testEnum.HandleRequest(storage, nil)
	testEnum = Ascii_protocol_enum{"delete", []string{"not_key"}, 0, 0, 0, 0, false, nil, ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != NOT_FOUND {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:10,代码来源:protocol_test.go

示例9: TestHandlingSuiteCas2

func TestHandlingSuiteCas2(t *testing.T) {
	var storage = cache.New(42)
	if !storage.Set(tools.NewStoredData([]byte("test1"), "key"), 0, 0, 0) {
		t.Fatalf("Unexpecting behavior ")
	}
	var testEnum = Ascii_protocol_enum{"cas", []string{"key"}, 1, 0, 42, 424242, false, make([]byte, 42), ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != NOT_FOUND {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:11,代码来源:protocol_test.go

示例10: TestHandlingSuiteGetMultiple

func TestHandlingSuiteGetMultiple(t *testing.T) {
	var storage = cache.New(42)
	var testEnum = Ascii_protocol_enum{"set", []string{"key1"}, 1, 0, 4, 0, false, []byte("TEST"), ""}
	testEnum.HandleRequest(storage, nil)
	testEnum = Ascii_protocol_enum{"set", []string{"key2"}, 1, 0, 4, 0, false, []byte("TEST"), ""}
	testEnum.HandleRequest(storage, nil)
	testEnum = Ascii_protocol_enum{"get", []string{"key1", "key2"}, 0, 0, 0, 0, false, nil, ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != "VALUE key1 1 4\r\nTEST\r\nVALUE key2 1 4\r\nTEST\r\nEND\r\n" {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:12,代码来源:protocol_test.go

示例11: TestHandlingSuiteIncrDecr2

func TestHandlingSuiteIncrDecr2(t *testing.T) {
	var storage = cache.New(42)
	var testEnum = Ascii_protocol_enum{"set", []string{"key"}, 1, 0, 6, 0, false, []byte("3.1459"), ""}
	testEnum.HandleRequest(storage, nil)
	testEnum = Ascii_protocol_enum{"incr", []string{"key"}, 0, 0, 0, 0, false, []byte("100"), ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != "ERROR\r\n" {
		t.Fatalf("Unexpected returned values of handling: ", err, string(res))
	}
	testEnum = Ascii_protocol_enum{"decr", []string{"key1"}, 0, 0, 0, 0, false, []byte("100"), ""}
	res, err = testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != "NOT_FOUND\r\n" {
		t.Fatalf("Unexpected returned values of handling: ", err, string(res))
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:15,代码来源:protocol_test.go

示例12: NewServer

// This public function raises up the server.
// Function receives following params:
// tcp_port string, which uses to open tcp socket at pointed port,
// udp_port string, which uses to open tcp socket at pointed port,
// address, which specified an only ip address which server will listen to,
// max_connections, sets a limit of maximal number of active connections,
// cas, flush - flags which forbids of usage such commands if value = true,
// verbosity - defines the dept of verbosity for server
// and bytes_of_memory, which uses for limiting allocated memory.
// Function returns a pointer to a server structure with filled and prepared to usage fields.
func NewServer(tcp_port string, udp_port string, address string, max_connections int, cas bool, flush bool,
	verbosity int, bytes_of_memory int64) *Server {
	server := new(Server)
	server.tcp_socket = nil
	server.tcp_port = tcp_port
	server.udp_port = udp_port
	server.cas_disabled = cas
	server.flush_disabled = flush
	server.connection_limit = max_connections
	server.listen_address = address
	server.storage = cache.New(bytes_of_memory)
	server.connections = make(map[string]net.Conn)
	server.Stat = statistic.New(bytes_of_memory, tcp_port, udp_port, max_connections, verbosity, cas, flush)
	server.Logger = NewServerLogger(verbosity)
	return server
}
开发者ID:UIKit0,项目名称:memorango,代码行数:26,代码来源:server.go

示例13: TestHandlingSuitePrepend2

func TestHandlingSuitePrepend2(t *testing.T) {
	var storage = cache.New(42)
	var testEnum = Ascii_protocol_enum{"set", []string{"key"}, 1, 0, 4, 0, false, []byte("TEST"), ""}
	res, err := testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != "STORED\r\n" {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
	testEnum = Ascii_protocol_enum{"prepend", []string{"key"}, 0, 0, 5, 0, false, []byte("TEST2"), ""}
	res, err = testEnum.HandleRequest(storage, nil)
	if err != nil || string(res) != "STORED\r\n" {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
	stored := tools.ExtractStoredData(storage.Get("key").Cacheable)
	if stored == nil || string(stored) != "TEST2TEST" {
		t.Fatalf("Stored value is invalid: ", err, stored)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:17,代码来源:protocol_test.go

示例14: TestHandlingSuiteGets1

func TestHandlingSuiteGets1(t *testing.T) {
	var storage = cache.New(42)
	var testEnum = Ascii_protocol_enum{"set", []string{"key"}, 1, 0, 4, 0, false, []byte("TEST"), ""}
	res, err := testEnum.HandleRequest(storage, nil)
	testEnum = Ascii_protocol_enum{"gets", []string{"key"}, 0, 0, 0, 0, false, nil, ""}
	res, err = testEnum.HandleRequest(storage, nil)
	item := storage.Get("key")
	if item == nil {
		t.Fatalf("Item wasn't stored")
	}
	cas := item.Cas_unique
	if cas == 0 {
		t.Fatalf("Cas unique wasn't set.")
	}
	match_str := "VALUE key 1 4 " + tools.IntToString(cas) + "\r\nTEST\r\nEND\r\n"
	if err != nil || string(res) != match_str {
		t.Fatalf("Unexpected returned values of handling: ", err, res, testEnum)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:19,代码来源:protocol_test.go

示例15: TestHandlingStatsRecording

func TestHandlingStatsRecording(t *testing.T) {
	var testEnum = Ascii_protocol_enum{"set", []string{"key"}, 1, 0, 2, 0, true, []byte("42"), ""}
	stats := stat.New(42, "9999", "8888", 1024, 2, true, true)
	var storage = cache.New(42)
	res, err := testEnum.HandleRequest(storage, stats)
	if err != nil || res == nil {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
	if stats.Commands == nil || stats.Commands["cmd_set"] != 1 {
		t.Fatalf("Wrong stats handling: ", stats.Commands)
	}

	stats = stat.New(42, "9999", "8888", 1024, 2, true, true)
	testEnum = Ascii_protocol_enum{"get", []string{"not_key"}, 0, 0, 0, 0, false, nil, ""}
	res, err = testEnum.HandleRequest(storage, stats)
	if err != nil || res == nil {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
	if stats.Commands == nil || stats.Commands["cmd_get"] != 1 || stats.Commands["get_misses"] != 1 {
		t.Fatalf("Wrong stats handling: ", stats.Commands)
	}

	stats = stat.New(42, "9999", "8888", 1024, 2, true, true)
	testEnum = Ascii_protocol_enum{"get", []string{"key"}, 0, 0, 0, 0, false, nil, ""}
	res, err = testEnum.HandleRequest(storage, stats)
	if err != nil || res == nil {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
	if stats.Commands == nil || stats.Commands["cmd_get"] != 1 || stats.Commands["get_hits"] != 1 {
		t.Fatalf("Wrong stats handling: ", stats.Commands)
	}

	stats = stat.New(42, "9999", "8888", 1024, 2, true, true)
	testEnum = Ascii_protocol_enum{"cas", []string{"key"}, 1, 0, 42, 424242, false, make([]byte, 42), ""}
	res, err = testEnum.HandleRequest(storage, stats)
	if err != nil || res == nil {
		t.Fatalf("Unexpected returned values of handling: ", err, res)
	}
	if stats.Commands == nil || stats.Commands["cas_badval"] != 1 {
		t.Fatalf("Wrong stats handling: ", stats.Commands)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:42,代码来源:protocol_test.go


注:本文中的tools/cache.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。