MCPcopy Create free account
hub / github.com/go-dev-frame/sponge / Set

Method Set

pkg/cache/memory.go:132–151  ·  view source on GitHub ↗

Set data

(_ context.Context, key string, val interface{}, expiration time.Duration)

Source from the content-addressed store, hash-verified

130
131// Set data
132func (m *memoryCache) Set(_ context.Context, key string, val interface{}, expiration time.Duration) error {
133 buf, err := encoding.Marshal(m.encoding, val)
134 if err != nil {
135 return fmt.Errorf("encoding.Marshal error: %v, key=%s, val=%+v ", err, key, val)
136 }
137 if len(buf) == 0 {
138 buf = NotFoundPlaceholderBytes
139 }
140 cacheKey, err := BuildCacheKey(m.KeyPrefix, key)
141 if err != nil {
142 return fmt.Errorf("BuildCacheKey error: %v, key=%s", err, key)
143 }
144 ok := m.client.SetWithTTL(cacheKey, buf, 0, expiration)
145 if !ok {
146 return errors.New("SetWithTTL failed")
147 }
148 m.client.Wait()
149
150 return nil
151}
152
153// Get data
154func (m *memoryCache) Get(_ context.Context, key string, val interface{}) error {

Callers 1

MultiSetMethod · 0.95

Calls 4

MarshalFunction · 0.92
BuildCacheKeyFunction · 0.85
ErrorfMethod · 0.80
WaitMethod · 0.45

Tested by

no test coverage detected