How to use aerospike as cache in Spring boot data jpa project with mysql and pgsql as datasources?

43 Views Asked by At

We have implemented our application in spring boot + spring data jpa + mysql&pgsql as databases. Can we use aerospike as cache only for my application ? There is no proper documentation or sample project available for reference.

1

There are 1 best solutions below

0
Roi Menashe On

There are 2 options to use Aerospike as a cache tier with Spring Boot:

  1. Use Spring Data Aerospike with Spring Cache features backed by Aerospike, with this you won't need to write the cache implementation logic, alternatively you can use annotation such as @Cacheable, CachePut and @CacheEvict that will be responsible for the actual implementation behind the scenes, here is a blog post about it: https://medium.com/aerospike-developer-blog/caching-with-spring-boot-and-aerospike-17b91267d6c

  2. Use Spring Data Aerospike to write your own cache implementation logic (try to search a record in Aerospike and if not found go to MySQL/PostgreSQL, write back to Aerospike etc...), you can use AerospikeRepository to reduce a lot of boilerplate code it won't be as easy as to use the first option but it will be more flexible.

I suggest to go to Spring Data Aerospike GitHub repository, go through the README and documentation and possibly blog posts/examples that suit your requirement: https://github.com/aerospike/spring-data-aerospike