掲示板

ServiceBuilder get timestamp of last cache

7年前 に M S によって更新されました。

ServiceBuilder get timestamp of last cache

New Member 投稿: 7 参加年月日: 13/05/06 最新の投稿
Hello everyone,
I'm using the ServiceBuilder to generate classes to connect to a different database.
When I’m getting data from the database by calling the …LocalServiceUtil class, the resulting entries are cached.
Sometimes another system changed the data in the external database and the results in Liferay are not up-to-date.
Is there a way to get a timestamp of the moment when the shown entity was cached from Liferay?
I want to show every user this timestamp. With the timestamp the user can decide if he wants to clear the cache with the function …Util.clearCache();

For example:
1. User A opens the webpage with the portlet for the first time.
2. The portlet gets the entity from the external database
3. User B opens the webpage
4. The portlet gets the entity from the cache
5. User B gets the result with the info, that the data was cached before (at the second step in this example)

Thanks for helping! emoticon
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: ServiceBuilder get timestamp of last cache

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
M S:
Is there a way to get a timestamp of the moment when the shown entity was cached from Liferay?


No.

I want to show every user this timestamp. With the timestamp the user can decide if he wants to clear the cache with the function …Util.clearCache();


Wrong answer. Users should not be touching the cache, should not know about the cache, and honestly should never know where data comes from just that it's there.

The right answer, though, is to look at the crux of the problem - unless otherwise indicated, SB will cache retrieved entities (to improve performance and reduce database load).

There's a key phrase there: "unless otherwise indicated". Since your database is updated externally, caching works against you and you should disable it for the entity. To do this, use the cache-enabled="false" attribute in your <entity /> tag.
7年前 に M S によって更新されました。

RE: ServiceBuilder get timestamp of last cache

New Member 投稿: 7 参加年月日: 13/05/06 最新の投稿
Hi David

thanks for pushing, or beating, me in the right direction :-)
You were right.
I changed the code logic and disabled the cache for all external databases.
Every other approach was getting worse while working on it...

<entity name="Entry" table="`Data Entry`" cache-enabled="false" data-source="extDataSource" session-factory="extSessionFactory" tx-manager="extTransactionManager">
    <column name="entryNo" db-name="`Entry No`" type="long" primary="true" />
    <column name="cost" db-name="`Cost`" type="double" />
</entity>