在@CacheEvict中有没有使用通配符的方法?
我有一个多租户应用程序,有时需要从租户的缓存中驱逐所有数据,但不是系统中所有租户的数据.
请考虑以下方法:
@Cacheable(value="users", key="T(Security).getTenant() + #user.key")
public List<User> getUsers(User user) {
...
}
Run Code Online (Sandbox Code Playgroud)
所以,我想做的事情如下:
@CacheEvict(value="users", key="T(Security).getTenant() + *")
public void deleteOrganization(Organization organization) {
...
}
Run Code Online (Sandbox Code Playgroud)
无论如何要做到这一点?
我试图通过Spring Boot和Spring Data实现鉴别器实现的多租户.
我创建了一个抽象类来表示一个多租户实体.与此类似的东西:
@MappedSuperclass
@FilterDefs({@FilterDef(name = "multi-tenant", parameters = {@ParamDef(name = "tenant", type = "string")})})
@Filter(name = "multi-tenant", condition = "tenant = :tenant")
public abstract class MultiTenantEntity extends GenericEntity {
@Transient
private transient String savedTenant;
@PostLoad
private void onLoad() throws Exception {
this.savedTenant = this.tenant;
onEntityModification();
}
@PrePersist
private void onPersist() {
if (getId() == null || getId().equals(0l)) {
tenant = SecurityUtil.getCurrentTenant();
}
}
@PreUpdate
@PreRemove
private void onEntityModification() throws Exception {
String currentTenant = SecurityUtil.getCurrentTenant();
if (!currentTenant.equals(tenant) || …Run Code Online (Sandbox Code Playgroud)