Caching with Relationships
See original GitHub issueI want to completely disable caching - I know this will be a performance hit but our table sizes are small and we’ll re-enable the caching once we configure the TCP Notification Server and have tested it in our environment/ with redundancy etc.
So, to disable the caching I set cacheType = none as follows and sure enough I see all application finds going to the db (sql logs and profiler show that)
<MithraObjectConfiguration
className="com.greenhedges.Account" cacheType="none"/>
<MithraObjectConfiguration
className="com.greenhedges.AccountAgreement" cacheType="none"/>
My issue is the one-to-many relationship are not refetched/queried from the db each time - e.g. say an Account can have n number of AccountAgreements:
<MithraObject objectType="transactional">
<PackageName>com.greenhedges</PackageName>
<ClassName>Account</ClassName>
<DefaultTable>account</DefaultTable>
...
<Relationship name="aggreements" relatedObject="AccountAgreement" cardinality="one-to-many" relatedIsDependent="true">
AccountAgreement.id = this.id
</Relationship>
</MithraObject>
Is there a way to force the relatedObjects to be reloaded always?
Issue Analytics
- State:
- Created 5 years ago
- Comments:10
Top Results From Across the Web
Managing Data Relationships in Distributed Cache - Alachisoft
Despite such powerful benefits, there is one issue faced by many in-memory caches. And that has to do with the fact that most...
Read more >Relationships Caching - Eloquent Query Cache
Relationships Caching. Relationships are using queries beneath. They can be intercepted and modified before the database is hit with the query.
Read more >What to Cache? caching all model with its relationships?
I am new to Caching. I know how it works but what are the things that must be cached? For example I have...
Read more >SQLAlchemy ORM Object caching with relationships and ...
Lets say I have object A that's in the cache and it has a relationship, A.B that was stored along with it in...
Read more >Effective parent child relationships with caching in JPA - Medium
Effective parent child relationships with caching in JPA · Motivation · Demonstration of a problem · Solution using caching · Missing table entities....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Eager graph loading in Reladomo is done via deep fetch on the list object, which means you can’t really use the
findByPrimaryKeyconvenience method if you want to load a graph eagerly. It’s not hard to use a list even if you want to load one object with some of its graph:When you use the list to eagerly fetch part of the graph, you’re effectively forcing a refresh in scenarios where the data may have changed in the db.
Deep fetching is always local to the piece of code: there is no way to globally change the behavior of calling a find (e.g. always forcing a certain relationship to be loaded eagerly). We believe forced graph loading in all contexts is an anti-pattern.
Most of the time, when you want to use a single object, there is no difference between eager and lazy loading with some exceptions:
Just to complete the picture, when you have an account object (regardless of whether you got it from a list with a deep fetch or findByPrimaryKey), a relationship traversal (calling
account.getAgreements()) will hit the cache if it can, and then the database if it must. In other words, relationships will lazily fetch data from the database if they must, but they are not affected by thecacheType="none"configuration (because then the piece of code I pasted would do very bad things). Another way to think about this is that the eager fetching via deep fetch is just priming the cache, not sewing a graph.As you’ve said, transactions don’t trust the cache at all, until they load something in that transaction from the database (which is really part of the locking scheme, with data refresh as a side effect). As far as eager/lazy fetching, the transactional context doesn’t make a difference (other than knowing when the cache is trustworthy).
A lot of this behavior is also predicated by the “uniquing” feature of Reladomo: each persistent object, identified by its PK, is guaranteed to have reference stability across the JVM.
Whether using a microservices architecture or not, you should think of your domain as a singular, coherent API. That means defining your domain in one place. Avoid defining the same thing in multiple places and avoid splitting your domain (especially where you’d be breaking natural relationships).
Your services can then use that consistent domain to serve their logic.
From a topology perspective, think of the domain as a single jar that you deploy to all your instances/services and have a single notification server for that cluster of services that use the same objects.