How do I use Spring's #Cacheable with Aerospike as the cache? - java

I just want to use Aerospike as the backing cache for Spring CacheManager.
Should I use spring data aerospike when I don't intend to use Aerospike as a data-store but only as a cache?
Is there any implementation available similar to HazelcastCacheManager or do I need to write my own?
Any help is appreciated.

Found this implementation for Aerospike Cache Manager.
https://github.com/shaileshmishra008/spring-cache-aerospike
I was able to write a version using this project as a reference.

There were some big changes in the Cache area in Spring Data Aerospike - starting from versions 2.5.0/3.0.0.
A Medium article about Caching with Spring Boot and Aerospike:
https://medium.com/aerospike-developer-blog/caching-with-spring-boot-and-aerospike-17b91267d6c

Related

How to save documents with CAS aware policy in Aerospike Spring Data

Could anyone show me how we could save documents with CAS aware policy in Spring Data Aerospike so that it uses the generation from the record to update the document with EXPECT_GEN_EQUAL generation policy?
I tried this:
Customer customer = customerRepositoryTest.findOne("335672888");
customer.setFieldX(some value)
customerRepository.save(customer);
But I found out the Aerospike Spring Data always use the NONE Generation Policy so that it always ignores the version property (generation) and overwrites the record when calling save.
Anyone got an idea? Thank you!
You should be using spring-data-aerospike dependency with groupId com.aerospike as it contains all contributed fixes to the project:
https://mvnrepository.com/artifact/com.aerospike/spring-data-aerospike
2.2.0.RELEASE is already supporting Spring Boot 2.2.
2.1.1.RELEASE is for Spring Boot 2.1.

How to test inmemory caching using Caffeine cache manager? (i.e. getting the count of entries in cache after caching, cache evict)

I want to get the details of entries in my custom cache after caching data or eviction of data.
I tried using actuator dependency to get 'actuator/metrics' path to get details but I'm getting empty tomcat server cache. There is no sign of my custom cache say myCache (the name which I passed into #Cacheable annotation value argument).
You tagged your question with Caffeine and Spring Boot, so I assume you use those two products.
If you use a recent Spring Boot and Caffeine, statistics will be automatically available at actuator/caches. If not, double check you have the needed libraries on your classpath and no configuration that enables another cache or disables caching at all, like spring.cache.type=none.
If you don't use Spring Boot, but just Spring, you need to add a CacheManager to your configuration, otherwise Spring defaults to the ConcurrentHashMap which does not have cache statistics.

Using MongoDB as Spring batch job repository

I am working on a spring batch solution and planning to use MongoDB as a job repository. I am looking for a references on this implementation but could not get any references. Then I was checking the spring-batch-core-3.0.7.RELEASE.jar, there I could not able to see MongoDB schema. Does this mean Spring batch does not support MongoDB as job repository?
That is correct. Mongo is not a suitable data store for the job repository due to the transactionality requirements of the job repository. The data store must be ACID compliant in order to be used which is why we have focused our efforts on relational databases for the repository implementation to date.
There is a recent (v1.0.0 in 2021-11-02) project to handle that, it's not managed by Spring team :
https://github.com/europeana/spring-batch-mongo
This library provides MongoDB JobRepository support for Spring Batch.
On official Spring side, there is this opened issue :
https://github.com/spring-projects/spring-batch/issues/877

How to configure Amazon Elasticache with Hibernate second level cache (Hibernate 5.0.7 & Wildfly 10.0.0)

I want to configure Hibernate's second level cache to use AWS Elasticache (currently trying to use memcached). I've looked at things like this, but can't seem to get it to work.
In the Hibernate 5.0 docs, it says that Wildfly automatically configures Hibernate's second level cache to use Inifinispan. Is there an easy way to disable this? Does configuring the cache to use elasticache (correctly) override this?
How can I configure the cache to use memcached in Hibernate 5? Several places say to set the property "hibernate.cache.provider_class" but the Hibernate 5.0 docs say that the property "hibernate.cache.region.factory_class" needs to be set to determine which provider to use. Also are old versions of hibernate-memcached (like this) still usable?

Caching in Spring Web service?

I need to load some data from DB to Cache on server start up.And once a request came, need to take the data from this cache.Also need to refresh cache in frequent intervals.It would be help if somebody provide way for achieving this.I am using Spring 3.1.
Thanks
There are lots of cache implementations available:
The Spring Cache abstraction
Ehcache (which is one possible provider for Spring Cache)
Guava's LoadingCache
Infinispan as user1516873 suggests
A plain ConcurrentHashMap from the JDK if you don't want more dependencies
etc.
I think this is what you are looking for:
Spring: hibernate + ehcache
As you will see my recommendation is to use hibernate second level cache and your problem will be fixed at configuration level.
Try Infinispan.
It modern, open source and easy to use cache. You can embed it and use directly, or use it as second level cache in hibernate.

Categories