當前位置: 首頁>>代碼示例>>Golang>>正文


Golang LRUCache.Get方法代碼示例

本文整理匯總了Golang中tools/cache.LRUCache.Get方法的典型用法代碼示例。如果您正苦於以下問題:Golang LRUCache.Get方法的具體用法?Golang LRUCache.Get怎麽用?Golang LRUCache.Get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tools/cache.LRUCache的用法示例。


在下文中一共展示了LRUCache.Get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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

示例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
	}
}
開發者ID:UIKit0,項目名稱:memorango,代碼行數:11,代碼來源:handling.go

示例3: 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

示例4: 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

示例5: 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

示例6: 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


注:本文中的tools/cache.LRUCache.Get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。