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 nocache option? #13

Open
godcong opened this issue Dec 21, 2021 · 8 comments
Open

add nocache option? #13

godcong opened this issue Dec 21, 2021 · 8 comments

Comments

@godcong
Copy link

godcong commented Dec 21, 2021

Example.

  1. Find data 1 (id: 1, name: test)
  2. Update data 1 (id: 1, name: nottest)
  3. Find data 1 -> this is the data that will be returned with name=test.

So, should an option be added in this case to turn off the cache?

@a8m
Copy link
Member

a8m commented Dec 26, 2021

Hey @godcong 👋

Did you see the entcache.Skip and the entcache.Evict options? I think in this case, your code can be written as follows:

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

Or:

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

We plan to introduce an automatic eviction mechanism at some point using (partial) SQL parsers. This will improve a lot the developer experience.

@godcong
Copy link
Author

godcong commented Dec 27, 2021

This function is possible, but it can only specify to the statement level.
Is there a skip option at table level?
There is a scenario where

  1. the query served by http is different.
  2. At this point I update the data in Pin, so the cached data in Pin is out of date.
  3. but unless I specify an eviction of a query, these caches will always be valid.

like this:

	save, err := db.Pin.Create().SetRid("abc123").Save(context.TODO())
        //query sql1
	pins, err := db.Pin.Query().All(context.TODO())
	fmt.Println("pins1:", pins)
	db.Pin.UpdateOne(save).SetRid("hijkl234").Save(context.TODO())
        //query sql2
	p, err := db.Pin.Query().First(entcache.Evict(context.TODO()))
	fmt.Println("pin:", p)
        //query sql3
	pins, err = db.Pin.Query().All(context.TODO())
	fmt.Println("pins2", pins)

In query sql2, I have evicted Pin's query, but the data is still out of date when using the all query.

And,
This statement does not seem to be running correctly:

u := client.T.Get(ctx, id)
u, _ = u.Update().SetName("nottest").Save(entcache.Evict(ctx))
	_, err := db.Pin.Create().SetRid("abc123").Save(context.TODO())
	p, err := db.Pin.Query().First(context.TODO())
	fmt.Println("pin:", p)
	pins, err := db.Pin.Query().All(context.TODO())
	fmt.Println("pins:", pins)
	p.Update().SetRid("hijkl123").Save(entcache.Evict(context.TODO()))
	p, err = db.Pin.Query().First(context.TODO())
	fmt.Println("pin:", p)
	pins, err = db.Pin.Query().All(context.TODO())
	fmt.Println("pins:", pins)

The 4 println statements all print out abc123
I changed db.Pin.Query().First(context.TODO()) to db.Pin.Get(context.TODO(), save.ID) getted the same result.

@dnson
Copy link

dnson commented Dec 28, 2021

@a8m could you please take a look on this?
I also experiment the same thing

@dnson
Copy link

dnson commented Dec 28, 2021

I looked at this code. It only delete the hash key of a specific query

image

@a8m
Copy link
Member

a8m commented Dec 28, 2021

Thanks, guys for the report. I'll give it a look

@godcong
Copy link
Author

godcong commented Jan 12, 2022

hi, @a8m
Has this gone anywhere?
I have an idea to add table fields to ctxOptions that
and change the Cache to [table]Cache.
Is this idea feasible?

@184104489
Copy link

@a8m could you please take a look on this?
I also experiment the same thing

@TcMits TcMits mentioned this issue Oct 5, 2022
@aonoa
Copy link

aonoa commented Jul 17, 2023

I don't think it's necessary to cache all tables

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

No branches or pull requests

5 participants