2

I have searched for a solution to caching that uses a database as its storage, but only come up with query caching. Are there any solutions out there to actually use a database as the storage mechanism for caching data?

To give some perspective, my issue is the following: I am consuming a web service resource that could be far more time-consuming than querying my database. As such, I want to cache the results of my web service requests in my database.

I realize I can do this by hand, but I though there has to be some existing solution out there that I can at least investigate if it is useful for my purposes.

Further info: My current project library consists of Java EE 7 and Hibernate.

I was hoping EHCache had something for me, but it seems to only provide memory or file-based solutions. The memory footprint for this particular cache would be too large. Also, this will run in a clustered environment, so the file-based solution would cause synchronization issues.

  • You have simular question here http://stackoverflow.com/questions/14026041/best-way-to-cache-restful-api-results-of-get-calls – Mario Petrovic Jul 19 '16 at 23:01

2 Answers2

0

RedHat's Infinispan has a couple of different JDBC based storage implemenations that allow what you ask for. Take a look at: http://infinispan.org/docs/stable/user_guide/user_guide.html#jdbc_based_cache_loaders (Disclaimer: I do not have usage experience with it, so I cannot say how stable it runs or how complex it is to setup).

In general using a database for cache persistence has Pro and Con arguments. The Pro argument is, that you might have easier deployment and resource management, because the database is already in place.

The Con argument is, that using a database means additional stress on the system. For cache updates, you will have a lot of database transactions forcing you disks to sync and your CPUs to wait for the IO to complete. For caching you don't need this behavior, because the data storage is temporary in nature.

cruftex
  • 5,545
  • 2
  • 20
  • 36
0

For these kind of issues I usually advice to use a solution based on Queue. These kind of solutions permit you to decouple client(your application) and server (web services endpoints) so you can perform this non-blocking pattern for:

  • Don't block the client
  • Perform the operation on received data when there are arrived
  • If you need, you can save the received data into a DB

I suggest you to use ActiveMQ to implement Queue capabilities and Apache Camel to to manage the services call/transformations/persistence.

Danilo Del Fio
  • 131
  • 2
  • 9