Set adds a new entry to the cache with a specified key and TTL. Parameters: - ctx: The context for the operation. - key: The cache key under which to store the value. - data: The value to be cached. - ttl: The time-to-live duration for the cached value. Returns an error if the caching operation fail
(ctx context.Context, key string, data interface{}, ttl time.Duration)
| 122 | // - ttl: The time-to-live duration for the cached value. |
| 123 | // Returns an error if the caching operation fails. |
| 124 | func (r *RedisCache) Set(ctx context.Context, key string, data interface{}, ttl time.Duration) error { |
| 125 | return r.cache.Set(&cache.Item{ |
| 126 | Ctx: ctx, |
| 127 | Key: key, |
| 128 | Value: data, |
| 129 | TTL: ttl, |
| 130 | }) |
| 131 | } |
| 132 | |
| 133 | // Get retrieves an entry from the cache based on the provided key. |
| 134 | // Parameters: |