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)
| 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. |
| 59 | func (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. |