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


Golang cache.LRUCache类代码示例

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


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

示例1: set

// Implements set method
func (enum *Ascii_protocol_enum) set(storage *cache.LRUCache) (string, error) {
	if storage.Set(tools.NewStoredData(enum.data_string, enum.key[0]), enum.flags, enum.exptime, 0) {
		return STORED, nil
	} else {
		return strings.Replace(SERVER_ERROR_TEMP, "%s", "Not enough memory", 1), errors.New("SERVER_ERROR")
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:8,代码来源:handling.go

示例2: Settings

// Function serialize sub command of stats "settings"
func (s *ServerStat) Settings(storage *cache.LRUCache) map[string]string {
	dict := make(map[string]string)
	dict["maxbytes"] = tools.IntToString(storage.Capacity())
	dict["maxconns"] = tools.IntToString(int64(s.Connections_limit))
	dict["tcpport"] = s.tcp
	dict["udpport"] = s.udp
	dict["verbosity"] = tools.IntToString(int64(s.verbosity))
	dict["num_goroutines"] = tools.IntToString(int64(runtime.NumGoroutine()))
	dict["evictions"] = "on" //TODO: to think about apportunity of another value.
	if storage.Crawler.Enabled() {
		dict["lru_crawler"] = "true"
	} else {
		dict["lru_crawler"] = "false"
	}
	dict["lru_crawler_sleep"] = tools.IntToString(int64(storage.Crawler.Sleep()))
	dict["lru_crawler_tocrawl"] = tools.IntToString(int64(storage.Crawler.ItemsPerRun))
	if s.cas_disabled {
		dict["cas_enabled"] = "false"
	} else {
		dict["cas_enabled"] = "true"
	}
	if s.flush_disabled {
		dict["flush_all_enabled"] = "false"
	} else {
		dict["flush_all_enabled"] = "true"
	}
	return dict
}
开发者ID:UIKit0,项目名称:memorango,代码行数:29,代码来源:stat.go

示例3: Serialize

// Function serialize statistic of server and storage and returns it as map of strings
func (s *ServerStat) Serialize(storage *cache.LRUCache) map[string]string {
	dict := make(map[string]string)
	dict["pid"] = tools.IntToString(int64(s.pid))
	dict["uptime"] = tools.IntToString(int64(s.uptime()))
	dict["time"] = tools.IntToString(int64(s.time()))
	dict["version"] = tools.VERSION
	dict["pointer_size"] = tools.IntToString(int64(pointer_size))
	secu, mcsecu, secs, mcsecs := s.rusage()
	dict["rusage_user"] = tools.IntToString(secu) + "." + tools.IntToString(mcsecu)
	dict["rusage_system"] = tools.IntToString(secs) + "." + tools.IntToString(mcsecs)
	dict["curr_items"] = tools.IntToString(int64(storage.Stats.Current_items))
	dict["total_items"] = tools.IntToString(int64(storage.Stats.Total_items))
	dict["bytes"] = tools.IntToString(s.bytes(storage.Capacity()))
	dict["curr_connections"] = tools.IntToString(int64(s.Current_connections))
	dict["total_connections"] = tools.IntToString(int64(s.Total_connections))
	dict["evictions"] = tools.IntToString(int64(storage.Stats.Evictions))
	dict["expired_unfetched"] = tools.IntToString(int64(storage.Stats.Expired_unfetched))
	dict["evicted_unfetched"] = tools.IntToString(int64(storage.Stats.Evicted_unfetched))
	dict["bytes_read"] = tools.IntToString(int64(s.Read_bytes))
	dict["bytes_written"] = tools.IntToString(int64(s.Written_bytes))
	dict["goroutines"] = tools.IntToString(int64(runtime.NumGoroutine()))
	dict["crawler_reclaimed"] = tools.IntToString(storage.Stats.Crawler_reclaimed)
	for key, value := range s.Commands {
		dict[key] = tools.IntToString(int64(value))
	}
	return dict
}
开发者ID:UIKit0,项目名称:memorango,代码行数:28,代码来源:stat.go

示例4: cas

// Implementation of Check And Set method
func (enum *Ascii_protocol_enum) cas(storage *cache.LRUCache) (string, error) {
	existed_item := storage.Get(enum.key[0])
	if existed_item != nil {
		if existed_item.Cas_unique == enum.cas_unique && existed_item.Cas_unique != 0 {
			return enum.set(storage)
		}
	}
	return NOT_FOUND, nil
}
开发者ID:UIKit0,项目名称:memorango,代码行数:10,代码来源:handling.go

示例5: touch

// Implements touch method
func (enum *Ascii_protocol_enum) touch(storage *cache.LRUCache) (string, error) {
	if item := storage.Get(enum.key[0]); item == nil {
		return NOT_FOUND, nil
	} else {
		if !storage.Set(item.Cacheable, item.Flags, enum.exptime, item.Cas_unique) {
			return strings.Replace(SERVER_ERROR_TEMP, "%s", "Not enough memory", 1), errors.New("SERVER_ERROR")
		}
		return "TOUCHED\r\n", nil
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:11,代码来源:handling.go

示例6: Items

// Serialization of sub command items
func (s *ServerStat) Items(storage *cache.LRUCache) map[string]string {
	dict := make(map[string]string)
	dict["number"] = tools.IntToString(int64(storage.Stats.Current_items))
	dict["age"] = tools.IntToString(time.Now().Unix() - storage.Oldest())
	dict["expired_unfetched"] = tools.IntToString(int64(storage.Stats.Expired_unfetched))
	dict["evicted_unfetched"] = tools.IntToString(int64(storage.Stats.Evicted_unfetched))
	dict["crawler_reclaimed"] = tools.IntToString(storage.Stats.Crawler_reclaimed)
	dict["outofmemory"] = tools.IntToString(storage.Stats.Outofmem)
	return dict
}
开发者ID:UIKit0,项目名称:memorango,代码行数:11,代码来源:stat.go

示例7: append

// Implements append method
func (enum *Ascii_protocol_enum) append(storage *cache.LRUCache) (string, error) {
	existed_item := storage.Get(enum.key[0])
	if existed_item == nil {
		return NOT_STORED, nil
	}
	existed_data := tools.ExtractStoredData(existed_item.Cacheable)
	if existed_data == nil {
		return NOT_STORED, nil
	}
	return enum.pending(storage, existed_item, append(existed_data, enum.data_string...)) // ...
}
开发者ID:UIKit0,项目名称:memorango,代码行数:12,代码来源:handling.go

示例8: get

// Implements get method
// Passed boolean param cas - defines of returning cas_unique
func (enum *Ascii_protocol_enum) get(storage *cache.LRUCache, cas bool) (string, error) {
	var result = ""
	for _, value := range enum.key {
		item := storage.Get(value)
		if item != nil {
			data := tools.ExtractStoredData(item.Cacheable)
			if data == nil {
				continue
			}
			result += "VALUE " + value + " " + tools.IntToString(int64(item.Flags)) + " " + tools.IntToString(int64(len(data)))
			if cas {
				cas_id := tools.GenerateCasId()
				storage.SetCas(value, cas_id)
				result += " " + tools.IntToString(cas_id)
			}
			result += "\r\n"
			result += string(data) + "\r\n"
		}
	}
	return result + "END\r\n", nil
}
开发者ID:UIKit0,项目名称:memorango,代码行数:23,代码来源:handling.go

示例9: lru_crawler

func (enum *Ascii_protocol_enum) lru_crawler(storage *cache.LRUCache) string {
	switch enum.key[0] {
	case "enable":
		err := storage.EnableCrawler()
		if err != nil {
			return strings.Replace(CLIENT_ERROR_TEMP, "%s", err.Error(), 1)
		}
		return "OK\r\n"
	case "disable":
		storage.DisableCrawler()
		return "OK\r\n"
	case "tocrawl":
		if len(enum.key) < 2 {
			return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Wrong parameters number.", 1)
		}
		amount, err := tools.StringToInt32(enum.key[1])
		if amount <= 0 || err != nil {
			return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Invalid value of passed param.", 1)
		}
		storage.Crawler.ItemsPerRun = uint(amount)
		return "OK\r\n"
	case "sleep":
		if len(enum.key) < 2 {
			return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Wrong parameters number.", 1)
		}
		amount, err := tools.StringToInt32(enum.key[1])
		if err != nil {
			return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Invalid value of passed param.", 1)
		}
		err = storage.Crawler.SetSleep(amount)
		if err != nil {
			return strings.Replace(CLIENT_ERROR_TEMP, "%s", err.Error(), 1)
		}
		return "OK\r\n"
	default:
		return strings.Replace(CLIENT_ERROR_TEMP, "%s", "Command is not implemented.", 1)
	}
}
开发者ID:UIKit0,项目名称:memorango,代码行数:38,代码来源:handling.go

示例10: fold

// Utility method, for joining common parts of incr/decr methods.
// Receives additional param sign, which defines operation: -1 or 1
func (enum *Ascii_protocol_enum) fold(storage *cache.LRUCache, sign int) (string, error) {
	if item := storage.Get(enum.key[0]); item != nil && (sign == 1 || sign == -1) {
		existed_data := tools.ExtractStoredData(item.Cacheable)
		if existed_data != nil {
			evaluated_data_for_existed, err_for_existed := tools.StringToInt64(string(existed_data))
			evaluated_data_for_passed, err_for_passed := tools.StringToUInt64(string(enum.data_string))
			if err_for_existed == nil && err_for_passed == nil {
				var result string
				if sign > 0 {
					result = tools.IntToString(evaluated_data_for_existed + int64(evaluated_data_for_passed))
				} else {
					result = tools.IntToString(evaluated_data_for_existed - int64(evaluated_data_for_passed))
				}
				if storage.Set(tools.NewStoredData([]byte(result), enum.key[0]), item.Flags, item.Exptime, 0) {
					return result + "\r\n", nil
				}
				return strings.Replace(SERVER_ERROR_TEMP, "%s", "Not enough memory", 1), errors.New("SERVER_ERROR")
			}
			return ERROR_TEMP, nil
		}
	}
	return NOT_FOUND, nil
}
开发者ID:UIKit0,项目名称:memorango,代码行数:25,代码来源:handling.go

示例11: add

// Implements add method
func (enum *Ascii_protocol_enum) add(storage *cache.LRUCache) (string, error) {
	if storage.Get(enum.key[0]) != nil {
		return NOT_STORED, nil
	}
	return enum.set(storage)
}
开发者ID:UIKit0,项目名称:memorango,代码行数:7,代码来源:handling.go

示例12: flush_all

// Implements flush all method
func (enum *Ascii_protocol_enum) flush_all(storage *cache.LRUCache) (string, error) {
	storage.FlushAll()
	return "OK\r\n", nil
}
开发者ID:UIKit0,项目名称:memorango,代码行数:5,代码来源:handling.go

示例13: delete

// Implements delete method
func (enum *Ascii_protocol_enum) delete(storage *cache.LRUCache) (string, error) {
	if storage.Flush(enum.key[0]) {
		return "DELETED\r\n", nil
	}
	return NOT_FOUND, nil
}
开发者ID:UIKit0,项目名称:memorango,代码行数:7,代码来源:handling.go


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