MCPcopy
hub / github.com/coocood/freecache / Set

Method Set

cache.go:59–66  ·  view source on GitHub ↗

Set sets a key, value and expiration for a cache entry and stores it in the cache. If the key is larger than 65535 or value is larger than 1/1024 of the cache size, the entry will not be written to the cache. expireSeconds <= 0 means no expire, but it can be evicted when cache is full.

(key, value []byte, expireSeconds int)

Source from the content-addressed store, hash-verified

57// the entry will not be written to the cache. expireSeconds <= 0 means no expire,
58// but it can be evicted when cache is full.
59func (cache *Cache) Set(key, value []byte, expireSeconds int) (err error) {
60 hashVal := hashFunc(key)
61 segID := hashVal & segmentAndOpVal
62 cache.locks[segID].Lock()
63 err = cache.segments[segID].set(key, value, hashVal, expireSeconds)
64 cache.locks[segID].Unlock()
65 return
66}
67
68// Touch updates the expiration time of an existing key. expireSeconds <= 0 means no expire,
69// but it can be evicted when cache is full.

Callers 15

SetIntMethod · 0.95
TestFreeCacheFunction · 0.95
TestOverwriteFunction · 0.95
TestGetWithExpirationFunction · 0.95
TestPeekWithExpirationFunction · 0.95
TestMultiGetFunction · 0.95
TestExpireFunction · 0.95
TestTouchFunction · 0.95
TestLargeEntryFunction · 0.95

Calls 2

hashFuncFunction · 0.85
setMethod · 0.80

Tested by 15

TestFreeCacheFunction · 0.76
TestOverwriteFunction · 0.76
TestGetWithExpirationFunction · 0.76
TestPeekWithExpirationFunction · 0.76
TestMultiGetFunction · 0.76
TestExpireFunction · 0.76
TestTouchFunction · 0.76
TestLargeEntryFunction · 0.76
TestIteratorFunction · 0.76