Skip to content

Commit

Permalink
add missing ttl to cache interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Southclaws committed Nov 19, 2024
1 parent 854c1ea commit 63d89fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/infrastructure/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

type Store interface {
Get(ctx context.Context, key string) (string, error)
Set(ctx context.Context, key string, object string) error
Set(ctx context.Context, key string, object string, ttl time.Duration) error
Delete(ctx context.Context, key string) error

HIncrBy(ctx context.Context, key string, field string, incr int64) (int, error)
Expand Down
6 changes: 4 additions & 2 deletions internal/infrastructure/cache/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ func (c *LocalCache) Get(ctx context.Context, key string) (string, error) {
return v.Value.(string), nil
}

func (c *LocalCache) Set(ctx context.Context, key string, value string) error {
func (c *LocalCache) Set(ctx context.Context, key string, value string, ttl time.Duration) error {
e := time.Now().Add(ttl)
c.local.Store(key, Entry{
Value: value,
Value: value,
Expiry: &e,
})
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/infrastructure/cache/redis/redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func (c *RedisCache) Get(ctx context.Context, key string) (string, error) {
return str, err
}

func (c *RedisCache) Set(ctx context.Context, key string, value string) error {
func (c *RedisCache) Set(ctx context.Context, key string, value string, ttl time.Duration) error {
cmd := c.client.B().
Set().
Key(key).
Value(value).
ExSeconds(int64(c.options.Expiration.Seconds())).
Ex(ttl).
Build()

err := c.client.Do(ctx, cmd).Error()
Expand Down

0 comments on commit 63d89fb

Please sign in to comment.