Cache interface provides the basic operations for a cache system. It includes methods for setting, getting, and deleting cached data.
| 29 | // Cache interface provides the basic operations for a cache system. |
| 30 | // It includes methods for setting, getting, and deleting cached data. |
| 31 | type Cache interface { |
| 32 | // Set stores a value in the cache with a specified time-to-live (TTL). |
| 33 | // Parameters: |
| 34 | // - ctx: The context for managing the request lifecycle. |
| 35 | // - key: The cache key under which the value will be stored. |
| 36 | // - value: The value to be stored in the cache. |
| 37 | // - ttl: The duration the value should be retained in the cache. |
| 38 | // Returns an error if the operation fails. |
| 39 | Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error |
| 40 | |
| 41 | // Get retrieves a value from the cache using a given key. |
| 42 | // Parameters: |
| 43 | // - ctx: The context for managing the request lifecycle. |
| 44 | // - key: The cache key to fetch the value. |
| 45 | // - data: The variable to store the fetched data. |
| 46 | // Returns an error if the key does not exist or retrieval fails. |
| 47 | Get(ctx context.Context, key string, data interface{}) error |
| 48 | |
| 49 | // Delete removes a value from the cache based on the provided key. |
| 50 | // Parameters: |
| 51 | // - ctx: The context for managing the request lifecycle. |
| 52 | // - key: The cache key to be deleted. |
| 53 | // Returns an error if the key cannot be deleted. |
| 54 | Delete(ctx context.Context, key string) error |
| 55 | } |
| 56 | |
| 57 | // RedisCache implements the Cache interface, using Redis as the underlying cache store. |
| 58 | // It leverages both Redis and local in-memory caching for efficient lookups. |
no outgoing calls
no test coverage detected