How to implement entity caching in cuba platform ?

Hi,
I am trying to implement caching in one of our application. I have gone through https://doc.cuba-platform.com/manual-6.2/entity_cache.html but could not find a way to implement that in the project. For example I will register few entites(Related to admin setup) for cache and each time I need those entities, it should provide the value from cache without going to database. My doubt is after modifying app.properties how to access the entities from cache ? Can DataManager or EntityManager be used to get data from cache ? Also how can we refresh the cached data ?

Hi,

I have gone through https://doc.cuba-platform.com/manual-6.2/entity_cache.html but could not find a way to implement that in the project.

Can you elaborate a little bit on what you tried out at what did not work? Generally i’d say Entity Caching is and should be a feature of the OR-Mapper. In case of CUBA it’s JPAs implementation EclipseLink. What CUBA additionally brings to the table is the synchronisation on the middleware layer in order to let any cluster member know of the cached entities and invalidation of entities throughout the whole cluster.

> and each time I need those entities, it should provide the value from cache without going to database
This is exactly what the EclipseLink provides. At it says in the docs: “Entity cache is used only when you retrieve entities by ID”.

Bye,
Mario

Hi Mario,
I tried the steps in the above link. It’s working fine while I am retrieving through primary key. But I want to add all data of a table in cache.
For example I have a three table like Country, State and City. Admin can add data into these tables and other user can use those data. In the registration page it has a lookup for country, state and District. All are dependent. States will come as per country and city should come as per state. Currently we are achieving this by using collection datasource.

I want to add all these data in cache so that it will not execute ant db script to pull the data. Please suggest how to achieve this ? Also suggest how can we refresh cached data like if admin adds a new city, it should come in lookup options for other users without restarting the server.

Thanks,
Saumm

Query cache is planned for the platform release 6.3. You will have the following API methods:
Query.setCacheable(boolean) for using the cache on the EntityManager level
LoadContext.Query.setCacheable(boolean) on the DataManager and datasources level.
The cache will be invalidated automatically on operations with cached entities.

1 Like