oak*_*oak 5 java spring spring-data-jpa spring-data-redis spring-cache
受到这个答案的启发,我尝试执行以下操作
@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);
}
然后使用这个接口来定义Used存储库
 @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);
 }
上面的缓存适用于findByType, findByCategory,findByCategoryAndWizardType_id
cacheable对于在 处定义的所有方法CacheableRepository。看来CacheConfig注释对SomeObjectRepo没有影响CacheableRepository。
为什么注释不起作用?有没有解决方法可以让这个结构发挥作用?
谢谢,橡树
| 归档时间: | 
 | 
| 查看次数: | 1108 次 | 
| 最近记录: |