Could someone please help to resolve the issue which is high priority for us.
Issue : The application is hosted in AWS with 3 instances for HA; when user logged in into the portal and browse the application , the below method verifyToken() gets triggered and the token gets stored in cache by using spring annotation @Cacheable and then gets evicted by using @CacheEvict when user LOGGED OUT from the portal ; we are able to still perform API operations by using that token with method verifyToken() since when CacheEvict is performed the token getting deleted from only one of the AWS instance and other 2 AWS nodes still having the token details and being returned until it gets expired. Question is how to get clear the token details from cache from all the nodes. These 3 AWS instances are running behind ELB
Please check below details for more details and let me know for any further clarifications.
Code :
@Cacheable(value = "sessions", key = "#token")
@Transactional
@SuppressWarnings("unchecked")
public Object verifyToken(final String token) {
return o;
}
@CacheEvict(value = "sessions", key = "#token")
@SuppressWarnings("unchecked")
public void clearToken(final String token) {
final List<Login> result = entitymanger.createNamedQuery("persis.find.token").setParameter("token", token).getResultList();
if (result != null && !result.isEmpty()) {
for (final Login pl : result) {
entitymanger.remove(pl);
}
}
}
@CacheEvict(value = "sessions", key = "#token")
public void evictSessionCache(final String token) {
// no implementation on purpose
}
- What version of Ehcache you are currently using;
- ehcache-spring-annotations-1.2.0.jar ; hibernate-ehcache-5.0.7.Final.jar;ehcache-core-2.6.11.jar
2. Paste the configuration for the Cache/CacheManager you have an issue with;
<diskStore path="java.io.tmpdir"/>
<defaultCache maxElementsInMemory="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
maxElementsOnDisk="10000000" diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"/>
<cache name="sessions" eternal="false" maxElementsInMemory="1000"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="300" memoryStoreEvictionPolicy="LRU"/>
3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate);
- spring version 4.3.12
- hibernate version 5.0.7
4. Providing JDK and OS versions maybe useful as well.
Java 8