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

I wonder what logic is used to determine the cache supported by this component #14

Open
gly-hub opened this issue Feb 23, 2024 · 2 comments
Assignees

Comments

@gly-hub
Copy link

gly-hub commented Feb 23, 2024

Your Question

I wonder what logic is used to determine the cache supported by this component? For example, I do a paging query, and the table is constantly inserted data, this component will not appear inconsistent data?

The document you expected this should be explained

Expected answer

@ktsivkov
Copy link
Collaborator

Hey @gly-hub,
Yes, you are right! If the data is not inserted through gorm's default create/update/delete methods, it would show inconsistent data.

As per v4 of this plugin what you could do is to call your Cacher implementation's Invalidate method, in order to invalidate the cached data.

If that's not possible in your use-case, you could set cache lifetime (let's say 5mins), this way you ensure that in the worst case you are going to have inconsistency for ~5min max.

TL;DR;
Some databases (i.e. MySQL) have internal caching mechanism in place. Ref: https://dev.mysql.com/doc/refman/5.7/en/query-cache.html
If none of these solved your problem you could look into some sort of database proxy (i.e. https://proxysql.com/ ) which can be used to achieve this goal.

@ktsivkov ktsivkov assigned ktsivkov and unassigned jinzhu Feb 23, 2024
@gly-hub
Copy link
Author

gly-hub commented Feb 26, 2024

Thank you very much for solving my doubts. There is also a bit of confusion: does any executed sql store a state in memory? If the data is changed across services, can the data cache be cleaned efficiently?

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

3 participants