Interface defines the operations a cache must support.
| 9 | |
| 10 | // Interface defines the operations a cache must support. |
| 11 | type Interface interface { |
| 12 | // Set adds a value to the cache with the default TTL. |
| 13 | Set(ctx context.Context, key string, value any) |
| 14 | |
| 15 | // SetWithTTL adds a value to the cache with a custom TTL. |
| 16 | SetWithTTL(ctx context.Context, key string, value any, ttl time.Duration) |
| 17 | |
| 18 | // Get retrieves a value from the cache. |
| 19 | Get(ctx context.Context, key string) (any, bool) |
| 20 | |
| 21 | // Delete removes a value from the cache. |
| 22 | Delete(ctx context.Context, key string) |
| 23 | |
| 24 | // Clear removes all values from the cache. |
| 25 | Clear(ctx context.Context) |
| 26 | |
| 27 | // Size returns the number of items in the cache. |
| 28 | Size() int64 |
| 29 | |
| 30 | // Close stops all background tasks and releases resources. |
| 31 | Close() error |
| 32 | } |
| 33 | |
| 34 | // item represents a cached value with metadata. |
| 35 | type item struct { |
no outgoing calls
no test coverage detected