本文整理汇总了Golang中tools/cache.LRUCache.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang LRUCache.Set方法的具体用法?Golang LRUCache.Set怎么用?Golang LRUCache.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tools/cache.LRUCache
的用法示例。
在下文中一共展示了LRUCache.Set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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")
}
}
示例2: 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
}
}
示例3: 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
}