Set实现子类getCacheNames();
public interface BasicOperation public abstract class CacheOperation implements BasicOperation public class CacheableOperation extends CacheOperation public class CacheEvictOperation extends CacheOperation public class CachePutOperation extends CacheOperationCacheOperation 简介
缓存动作的基础抽象类,构造器模式构造CacheOperation实例;
核心代码// 名称 private final String name; // 缓存标识符集合 private final SetCacheableOperation 简介cacheNames; // 缓存KEY private final String key; // 缓存KEY生成器 private final String keyGenerator; // 缓存管理器 private final String cacheManager; // 缓存解析器 private final String cacheResolver; // 先决条件 private final String condition; // toString值 private final String toString; public Set getCacheNames() { return this.cacheNames; } protected CacheOperation(Builder b) { this.name = b.name; this.cacheNames = b.cacheNames; this.key = b.key; this.keyGenerator = b.keyGenerator; this.cacheManager = b.cacheManager; this.cacheResolver = b.cacheResolver; this.condition = b.condition; this.toString = b.getOperationDescription().toString(); } @Override public boolean equals(@Nullable Object other) { return (other instanceof CacheOperation && toString().equals(other.toString())); } @Override public int hashCode() { return toString().hashCode(); } @Override public final String toString() { return this.toString; } public abstract static class Builder { // 名称 private String name = ""; // 缓存标识符集合 private Set cacheNames = Collections.emptySet(); // 缓存KEY private String key = ""; // 缓存KEY生成器 private String keyGenerator = ""; // 缓存管理器 private String cacheManager = ""; // 缓存解析器 private String cacheResolver = ""; // 先决条件 private String condition = ""; protected StringBuilder getOperationDescription() { StringBuilder result = new StringBuilder(getClass().getSimpleName()); result.append('[').append(this.name); result.append("] caches=").append(this.cacheNames); result.append(" | key='").append(this.key); result.append("' | keyGenerator='").append(this.keyGenerator); result.append("' | cacheManager='").append(this.cacheManager); result.append("' | cacheResolver='").append(this.cacheResolver); result.append("' | condition='").append(this.condition).append('''); return result; } public abstract CacheOperation build(); }
缓存添加动作的具体实现;
核心代码// 后决条件 @Nullable private final String unless; // 同步标识 private final boolean sync; public CacheableOperation(CacheableOperation.Builder b) { super(b); this.unless = b.unless; this.sync = b.sync; } public static class Builder extends CacheOperation.Builder { // 后决条件 @Nullable private String unless; // 同步标识 private boolean sync; @Override protected StringBuilder getOperationDescription() { StringBuilder sb = super.getOperationDescription(); sb.append(" | unless='"); sb.append(this.unless); sb.append('''); sb.append(" | sync='"); sb.append(this.sync); sb.append('''); return sb; } @Override public CacheableOperation build() { return new CacheableOperation(this); } }CacheEvictOperation 简介
缓存清除动作的具体实现;
核心代码// 全部清除标识 private final boolean cacheWide; // 在方法执行前执行标识 private final boolean beforeInvocation; public CacheEvictOperation(CacheEvictOperation.Builder b) { super(b); this.cacheWide = b.cacheWide; this.beforeInvocation = b.beforeInvocation; } public static class Builder extends CacheOperation.Builder { // 全部清除标识 private final boolean cacheWide; // 在方法执行前执行标识 private final boolean beforeInvocation; @Override protected StringBuilder getOperationDescription() { StringBuilder sb = super.getOperationDescription(); sb.append(','); sb.append(this.cacheWide); sb.append(','); sb.append(this.beforeInvocation); return sb; } @Override public CacheEvictOperation build() { return new CacheEvictOperation(this); } }CachePutOperation 简介
缓存更新动作的具体实现;
核心代码// 后决条件 @Nullable private final String unless; public CachePutOperation(CachePutOperation.Builder b) { super(b); this.unless = b.unless; } public static class Builder extends CacheOperation.Builder { // 后决条件 private final String unless; @Override protected StringBuilder getOperationDescription() { StringBuilder sb = super.getOperationDescription(); sb.append(" | unless='"); sb.append(this.unless); sb.append('''); return sb; } @Override public CachePutOperation build() { return new CachePutOperation(this); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)