| 108 | } |
| 109 | |
| 110 | func (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 | |
| 135 | func (m *MemoryConnector) Get(ctx context.Context, index, partitionKey, rangeKey string, _ interface{}) ([]byte, error) { |
| 136 | if index == ConnectorReverseIndex && strings.HasSuffix(partitionKey, "*") { |