spring数据仓库的缓存默认方法
我正在使用spring数据和缓存 是否有任何方法可以将缓存放在存储库(findOne…)的默认方法上,而无需在我们创建的接口中重新声明这些方法spring数据仓库的缓存默认方法,spring,spring-data,spring-cache,Spring,Spring Data,Spring Cache,我正在使用spring数据和缓存 是否有任何方法可以将缓存放在存储库(findOne…)的默认方法上,而无需在我们创建的接口中重新声明这些方法 public interface AccountOperationRepository extends JpaRepository<AccountOperation, Long>{ @Cacheable(value = "myCache") AccountOperation findOne(Long id) } 公共接口Ac
public interface AccountOperationRepository extends JpaRepository<AccountOperation, Long>{
@Cacheable(value = "myCache")
AccountOperation findOne(Long id)
}
公共接口AccountOperationRepository扩展了JpaRepository{
@可缓存(value=“myCache”)
AccountOperation findOne(长id)
}
您可以实现自己的dao,有关基本信息:
public interface CachedDAO<T, ID extends Serializable> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
@Cacheable(value = "cacheValue1")
T findOne(ID id);
@Cacheable(value = "cacheValue2")
List<T> findAll();
@Cacheable(value = "cacheValue3")
Page<T> findAll(Pageable pageable);
//Evict because you want to modify value
@CacheEvict(value = "cacheValue4", allEntries = true)
<S extends T> S save(S entity);
//the same with delete
@CacheEvict(value = "cacheValue5", allEntries = true)
void delete(ID id);
}
public interface CachedDAO扩展了JpaRepository、JpaSpecificationExecutor{
@可缓存(value=“cacheValue1”)
T findOne(ID);
@可缓存(value=“cacheValue2”)
列出findAll();
@可缓存(value=“cacheValue3”)
页面findAll(可分页可分页);
//退出,因为您要修改值
@cacheexecute(value=“cacheValue4”,allEntries=true)
S save(S实体);
//删除也一样
@cacheexecute(value=“cacheValue5”,allEntries=true)
作废删除(ID);
}
您需要多搜索一点,希望能有所帮助。我已经在spring数据存储库中这样使用过它
@Cacheable(value = "accountIds",sync = true)
default List<AccountDetailDTO> getAccountIds() {
findById();
}
@Cacheable(value=“accountIds”,sync=true)
默认列表getAccountId(){
findById();
}
每个对象都将使用相同的名称作为缓存?