Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flexible the cacheconn #3995

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/stores/sqlc/cachedsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (cc CachedConn) GetCacheCtx(ctx context.Context, key string, v any) error {
return cc.cache.GetCtx(ctx, key, v)
}

func(cc CachedConn)GetRawConnNoCache()sqlx.SqlConn{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When NewConn is used, the conn is passed in from the outside. It is of little significance to provide RawConn here. If you really want to get it, you can save it by the business itself, or explain the value of providing the new method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your explanation is reasonable,but this situation need be token care .In the most of environment, i can only declare a cacheConn variable in my servercontext obviously,but according to the real environment,i must to use the conn which skip the cache level in some condition query,because the series query will hit rarely. To make easier operation,i must expose this sqlx.SqlConn to directly use the NonCache query.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the implementation simple, I think it's more straightforward that you keep the reference on your own.

return cc.db
}

// Exec runs given exec on given keys, and returns execution result.
func (cc CachedConn) Exec(exec ExecFn, keys ...string) (sql.Result, error) {
execCtx := func(_ context.Context, conn sqlx.SqlConn) (sql.Result, error) {
Expand Down