-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested
Description
CRUDImpl
package com.nk.realstateapi.services.impl;
import com.nk.realstateapi.repositories.IGenericRepository;
import com.nk.realstateapi.services.ICRUD;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
public abstract class CRUDImpl<T, K> implements ICRUD<T, K> {
protected abstract IGenericRepository<T, K> getRepo();
@Override
@CacheEvict(value = "#{T(this).getCacheName()}", allEntries = true)
public T save(T t) throws Exception {
return getRepo().save(t);
}
@Override
@CacheEvict(value = "#{T(this).getCacheName()}", allEntries = true)
public T update(T t, K k) throws Exception {
getRepo().findById(k).orElseThrow(() -> new Exception("ID NOT FOUND: " + k));
return getRepo().save(t);
}
@Override
@Cacheable(value = "#{T(this).getCacheName()}", keyGenerator = "versionedKeyGenerator")
public List<T> readAll() throws Exception {
return getRepo().findAll();
}
@Override
@Cacheable(value = "#{T(this).getCacheName()}", keyGenerator = "versionedKeyGenerator")
public T readById(K k) throws Exception {
return getRepo().findById(k).orElseThrow(() -> new Exception("ID NOT FOUND: " + k));
}
@Override
@CacheEvict(value = "#{T(this).getCacheName()}", allEntries = true)
public void delete(K k) throws Exception {
getRepo().findById(k).orElseThrow(() -> new Exception("ID NOT FOUND: " + k));
getRepo().deleteById(k);
}
protected String getCacheName() {
return this.getClass().getSimpleName() + "Cache";
}
}Redis
127.0.0.1:6379> keys *
1) "#{T(this).getCacheName()}::realStateAPI:v1:CompanyServiceImpl:readAll"
2) "#{T(this).getCacheName()}::realStateAPI:v1:HousingServiceImpl:readAll"Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingquestionFurther information is requestedFurther information is requested