cache icon indicating copy to clipboard operation
cache copied to clipboard

feat: support-keepttl

Open icbd opened this issue 6 months ago • 0 comments

When we try to pass -1 into TTL, we are always disappointed to find that it does not work as expected.

When we saw the source code if item.TTL < 0 { return 0 }, we were a little surprised.

I do understand that for a cache, non-expiring keys are risky.

However, I believe that everyone knows what they are doing when setting TTL to -1, which is consistent with the Redis parameters.

How to use:

// from readme demo code
err := mycache.Once(&cache.Item{
		Key:   "mykey",
		Value: obj,
		TTL:   redis.KeepTTL, // Changed here
		Do: func(*cache.Item) (interface{}, error) {
			return &Object{
				Str: "mystring",
				Num: 42,
			}, nil
		},
	})

icbd avatar Aug 01 '25 11:08 icbd