Liferay internally uses EhCache for implementing cache for the database. However it is possible to implement ehcache in our custom code.
You can see the additional knowledge about it here.
But this how the liferay caches the database it is using. Apart form this, we can also use ehcache for our custom implementation. Lets see how this can be done:
Here we have two function setting and getting values in cache. We can import the class and use in our code.
Hope this will help.