ATG RepositoryItem getPropertyValue, no cache, no

2019-09-09 21:58发布

If I have an ATG Nucleus Repository Item that is not cacheable (ATG/Nucleus simple cache is disabled) AND I'm not in a transaction, the following results in two queries to the database.

The following code results in a db query for every property. repositoryItem.getPropertyValue("columnA"); repositoryItem.getPropertyValue("columnB");

If debugging for the user entity is enabled you would see the following log statements ever each call:

repositoryItem.getPropertyValue("columnA"); DEBUG loadingPropertyFromDatabase(user:ID_1.columnA, column_a_value) property is not cacheable caching disabled for this transaction DEBUG loadingPropertyFromDatabase(user:ID_1.columnB, column_b_value) property is not cacheable caching disabled for this transaction DEBUG getPropertyValue(user:ID_1.columnA) -> "column_a_value" (value from database)

repositoryItem.getPropertyValue("columnB"); DEBUG loadingPropertyFromDatabase(user:ID_1.columnA, column_a_value) property is not cacheable caching disabled for this transaction DEBUG loadingPropertyFromDatabase(user:ID_1.columnB, column_b_value) property is not cacheable caching disabled for this transaction DEBUG getPropertyValue(user:ID_1.columnB) -> "column_b_value" (value from database)

We cannot enable caching, due to how the object is being access/updated by other systems.

I also do not want to create a transaction for a read only query of the entity.

If I was using Hibernate, the Hibernate session would keep a state within the session, even if I was not in a transaction. That doesn't seem to be the case with ATG/Nucleus. Is there any way I can get this type of behavior or a thread level cache?

In looking at documentation and walking through the code via debugger (which is difficult w/out source), I am not having any luck finding a work around.

Thanks!

1条回答
霸刀☆藐视天下
2楼-- · 2019-09-09 22:06

You need to wrap the getPropertyValue calls with a transaction which will save the results of the database queries into the temporary transaction cache. That will prevent the repository from going back to the database for every getPropertyValue call.

You also want to ensure that all the properties you are accessing are part of the same property group (as described here). The first load of the item from the database will pull in the properties in the same group as the ID property. This combined with the transaction cache will significantly reduce the number of database queries.

I also do not want to create a transaction for a read only query of the entity.

I don't understand why you wouldn't want to explicitly demarcate a transaction. Every getPropertyValue call will automatically create (and end) a transaction if one isn't already present. So in your example, you would have 2 transactions implicitly created for you. Why not just create 1 transaction explicitly?

查看更多
登录 后发表回答