List questions first:
1. Does graph instance cache any orient element it encountered, no matter the tx commit or the graph got returned to pool?
2. Does a tx commit updates the cache of another graph/thread? If no, it means the cache doesn't behavior like a unified cache such as hibernate 2nd-level cache.
Sorry I forgot to mention orientdb version. I tried 2.1.5, and then 2.1.7, and then 2.1.8. However I don't think it quite relates to minor version.
I ask the questions since I encounter troubles recently with orientdb.
I try to use Vert.x 3 and OrientDB (Embeded Server) in an application. Vert.x is aync, thus the thread local mode is not usable anymore. The solution is to use OrientGraphFactory to setup a pool(using plocal). For each database task, retrieve a graph instance and then call makeActive. The code is like this (language is kotlin):
fun graph(factory: OrientGraphFactory = Injekt.get()): OrientGraph {
val g = factory.tx
g.makeActive()
return g
}
If the task does modification, graph.commit will get invoked, and finally, graph.shutdown will be called.
And all databse tasks run in work threads, however, there's no static bound between graph instances and threads.
The trouble I encountered is the same query conditions get different results. For example,
an order, with status "Payed" at some point;
and some time later, another operation changes the status to "End";
on a web page, it shows the result as "End" sometimes and "Payed" for the rest.
After this question happened, I try to replace tx with noTx when no tx needed, however the question continued. Now I try to invalidate localcache.
fun graph(factory: OrientGraphFactory = Injekt.get(), txRequired: Boolean = true): OrientBaseGraph {
val g = if (txRequired) factory.tx else factory.noTx
g.makeActive()
g.rawGraph.localCache.invalidate()
return g
}
I'll update the result tomorrow.
And according to my reading of the code of orientdb, the transaction will begin immediately after graph retrieved and committed, not when a modification occurred that the manual described.