MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / Cache

Method Cache

lib/valkeycache/cache.go:75–96  ·  view source on GitHub ↗

Cache stores a value in the cache.

(
	ctx context.Context,
	key K,
	in V,
	options ...cachetypes.CacheOption,
)

Source from the content-addressed store, hash-verified

73
74// Cache stores a value in the cache.
75func (c *ValkeyDataCache[K, V]) Cache(
76 ctx context.Context,
77 key K,
78 in V,
79 options ...cachetypes.CacheOption,
80) error {
81 // Build default config for cache operation
82 cacheCfg := cachetypes.NewCacheConfig(c.ttl)
83
84 // Apply options to config
85 for _, opt := range options {
86 opt(cacheCfg)
87 }
88
89 err := c.client.Do(ctx, c.client.B().Set().Key(c.cacheKey(key)).
90 Value(valkey.BinaryString(in)).Ex(cacheCfg.GetTTL()).Build()).Error()
91 if err != nil {
92 return err
93 }
94
95 return nil
96}
97
98// Get retrieves a value from the cache.
99// It returns cachetypes.ErrCachedDataNotFound if it does not exist.

Callers

nothing calls this directly

Calls 5

cacheKeyMethod · 0.95
GetTTLMethod · 0.95
DoMethod · 0.65
ErrorMethod · 0.45
BuildMethod · 0.45

Tested by

no test coverage detected