Inspired by this answer I tried to do the following
@NoRepositoryBean
public interface CacheableRepository<T, ID extends Serializable>
extends JpaRepository<T, ID>, JpaSpecificationExecutor<T>, PagingAndSortingRepository<T, ID> {
@Cacheable()
T findOne(ID id);
@Cacheable()
List<T> findAll();
@Cacheable()
Page<T> findAll(Pageable pageable);
@CacheEvict(allEntries = true)
<S extends T> S save(S entity);
@CacheEvict(allEntries = true)
void delete(ID id);
}
Then use this interface to define the Used repository
@CacheConfig(cacheNames={"uniqueCache"})
public interface SomeObjectRepo extends CacheableRepository<SomeObject, Long> {
@Cacheable(key = "someobject+#p0")
List<SomeObject> findByType(Integer type);
@Cacheable(key = "someobject+#p0")
List<SomeObject> findByCategory(String field);
@Cacheable(key="someobject+#p0.concat(#p1)")
List<SomeObject> findByCategoryAndWizardType_id(String field,Integer id);
}
Works:
The cache above work for findByType
,findByCategory
,findByCategoryAndWizardType_id
Does not work:
For all the cacheable
methods defined at CacheableRepository
. It seems that the CacheConfig
annotation on SomeObjectRepo
does not effect the CacheableRepository
.
My question:
Why the annotation does not work? Is there a workaround to get this structure to work?
Thanks, Oak