From 3726851c7fbbf3f23c465f9a5c0dc1cfd3e7e36b Mon Sep 17 00:00:00 2001 From: hc <530176577@qq.com> Date: Sun, 28 May 2023 12:27:30 +0800 Subject: [PATCH] feat: sqlc add SetCacheWithExpire method (#3249) Co-authored-by: luohancai --- core/stores/sqlc/cachedsql.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/stores/sqlc/cachedsql.go b/core/stores/sqlc/cachedsql.go index 27692636..d8928105 100644 --- a/core/stores/sqlc/cachedsql.go +++ b/core/stores/sqlc/cachedsql.go @@ -214,6 +214,16 @@ func (cc CachedConn) SetCacheCtx(ctx context.Context, key string, val any) error return cc.cache.SetCtx(ctx, key, val) } +// SetCache sets v into cache with given key, using given expire. +func (cc CachedConn) SetCacheWithExpire(key string, val any, expire time.Duration) error { + return cc.SetCacheWithExpireCtx(context.Background(), key, val, expire) +} + +// SetCacheCtx sets v into cache with given key, using given expire. +func (cc CachedConn) SetCacheWithExpireCtx(ctx context.Context, key string, val any, expire time.Duration) error { + return cc.cache.SetWithExpireCtx(ctx, key, val, expire) +} + // Transact runs given fn in transaction mode. func (cc CachedConn) Transact(fn func(sqlx.Session) error) error { fnCtx := func(_ context.Context, session sqlx.Session) error {