Feature: support adding custom cache to mongoc and sqlc (#1313)

* merge

* Feature: support adding custom cache to mongoc and sqlc
This commit is contained in:
MarkJoyMa
2021-12-18 22:45:07 +08:00
committed by GitHub
parent b299f350be
commit 3e6c217408
2 changed files with 22 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package sqlc
import (
"database/sql"
"log"
"time"
"github.com/tal-tech/go-zero/core/stores/cache"
@@ -55,6 +56,17 @@ func NewConn(db sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) CachedCon
}
}
// NewConnWithCache returns a CachedConn with a custom cache.
func NewConnWithCache(db sqlx.SqlConn, c cache.Cache) CachedConn {
if c == nil {
log.Fatal("Invalid cache component")
}
return CachedConn{
db: db,
cache: c,
}
}
// DelCache deletes cache with keys.
func (cc CachedConn) DelCache(keys ...string) error {
return cc.cache.Del(keys...)