Transaction cache layer to simplify its use? #8272
pepoospina
started this conversation in
General
Replies: 1 comment
-
sorry for the ping. Is there a tool that do this already? I find it extremely useful |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Transactions have a significant limitation which is that you cannot read after you have already made one write to the DB.
On our app, we are using a Transaction manager that keeps all the writes in a memory cache, use it to return reads (if there is a cached write apply it to the document being read), and then, after everything is done, execute all writes at once.
I was not able to find an official library for this. Do you know of anything like it?
This is our code. You can also switch between a Transaction and a Batch operation. I thought this was a cool tool and so I wanted to share the code here.
Its not professional code, and there are probably many rough corners, but it could help inspire others or maybe an official tool by Firebase.
TransactionManager
DBInstance
And an example of how we use it:
We need to send the manager as a parameter from the upper controller layers, down to our DB repository services. But it works just fine. Also, writes are synchronous operations (as they operate on the cache).
Beta Was this translation helpful? Give feedback.
All reactions