MCPcopy Create free account
hub / github.com/erpc/erpc / Set

Method Set

data/memory.go:110–133  ·  view source on GitHub ↗
(ctx context.Context, partitionKey, rangeKey string, value []byte, ttl *time.Duration)

Source from the content-addressed store, hash-verified

108}
109
110func (m *MemoryConnector) Set(ctx context.Context, partitionKey, rangeKey string, value []byte, ttl *time.Duration) error {
111 m.logger.Debug().Str("partitionKey", partitionKey).Str("rangeKey", rangeKey).Int("len", len(value)).Msg("writing to memory (ristretto)")
112
113 key := fmt.Sprintf("%s:%s", partitionKey, rangeKey)
114
115 if ttl != nil && *ttl > 0 {
116 m.cache.SetWithTTL(key, value, 0, *ttl)
117 } else {
118 m.cache.Set(key, value, 0)
119 }
120
121 /**
122 * TODO Find a better way to store a reverse index for cache entries with unknown block ref (*):
123 */
124 if strings.HasPrefix(partitionKey, "evm:") && !strings.HasSuffix(partitionKey, "*") {
125 parts := strings.SplitAfterN(partitionKey, ":", 3)
126 if len(parts) >= 2 {
127 wildcardPartitionKey := parts[0] + parts[1] + "*"
128 m.cache.Set(memoryReverseIndexPrefix+"#"+wildcardPartitionKey+"#"+rangeKey, []byte(partitionKey), 0)
129 }
130 }
131
132 return nil
133}
134
135func (m *MemoryConnector) Get(ctx context.Context, index, partitionKey, rangeKey string, _ interface{}) ([]byte, error) {
136 if index == ConnectorReverseIndex && strings.HasSuffix(partitionKey, "*") {

Calls 1

SetMethod · 0.65