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

add key holder #24

Closed
wants to merge 1 commit into from
Closed

add key holder #24

wants to merge 1 commit into from

Conversation

TcMits
Copy link

@TcMits TcMits commented Oct 5, 2022

Hi @a8m

Inspired by cachops, i add key holders which created in onClose function. Each holder is equivalent with record(s). It make easier to evict keys, which are related to record(s).

Example:

expectQuery(evictCtx, t, drv, "SELECT name FROM users LIMIT 1 OFFSET 0", []interface{}{"a8m"}) // evicted
expectQuery(ctx, t, drv, "SELECT name FROM users", []interface{}{"a8m", "a9m"}) // evicted too
expectQuery(ctx, t, drv, "SELECT name FROM users LIMIT 1 OFFSET 1", []interface{}{"a9m"}) // still in cache

Its also related to issue #13. When update a record with UpdateOne, ent will fetch record after updating.

u := client.T.Get(ctx, id)
u, _ = u.Update().SetName("nottest").Save(entcache.Evict(ctx))

graph.go

	if !update.Empty() {
		var res sql.Result
		query, args := update.Query()
		if err := tx.Exec(ctx, query, args, &res); err != nil {
			return err
		}
		...
	}
	...
	rows := &sql.Rows{}
	query, args := selector.Query()
	if err := tx.Query(ctx, query, args, rows); err != nil {
		return err
	}
	return u.scan(rows)

@TcMits TcMits closed this Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant