class AbstractExternalCache<K, V> extends AbstractCache<K, V> {

    private ExternalCacheConfig<K, V> config;

    public AbstractExternalCache(ExternalCacheConfig<K, V> config) {
        this.config = config;
        checkConfig();
    }

    protected void checkConfig() {
        if (config.getValueEncoder() == null) {
            throw new CacheConfigException("no value encoder");
        }
        if (config.getValueDecoder() == null) {
            throw new CacheConfigException("no value decoder");
        }
        if (config.getKeyPrefix() == null) {
            throw new CacheConfigException("keyPrefix is required");
        }
    }

    public byte[] buildKey(K key) {
        try {
            Object newKey = key;
            if (config.getKeyConvertor() != null) {
                if (config.getKeyConvertor() instanceof KeyConvertor) {
                    if (!isPreservedKey(key)) {
                        // since 2.7.3 KeyConvertor extends Function<Object, Object>
                        newKey = config.getKeyConvertor().apply(key);
                    }
                } else {
                    // before 2.7.3, KeyConvertor is interface only place some constants.
                    // "key convertor" is Function<Object, Object> and can't process byte[] and String
                    if (key instanceof byte[]) {
                        newKey = key;
                    } else if (key instanceof String) {
                        newKey = key;
                    } else {
                        newKey = config.getKeyConvertor().apply(key);
                    }
                }
            }
            return ExternalKeyUtil.buildKeyAfterConvert(newKey, config.getKeyPrefix());
        } catch (IOException e) {
            throw new CacheException(e);
        }
    }

    private boolean isPreservedKey(Object key) {
        if (key instanceof byte[]) {
            byte[] keyBytes = (byte[]) key;
            return endWith(keyBytes, RefreshCache.LOCK_KEY_SUFFIX)
                    || endWith(keyBytes, RefreshCache.TIMESTAMP_KEY_SUFFIX);
        }
        return false;
    }

    private boolean endWith(byte[] key, byte[] suffix) {<FILL_FUNCTION_BODY>}

}

        int len = suffix.length;
        if (key.length < len) {
            return false;
        }
        int startPos = key.length - len;
        for (int i = 0; i < len; i++) {
            if (key[startPos + i] != suffix[i]) {
                return false;
            }
        }
        return true;
    
<methods>public non-sealed void <init>() ,public final CacheGetResult<V> GET(K) ,public final MultiGetResult<K,V> GET_ALL(Set<? extends K>) ,public final com.alicp.jetcache.CacheResult PUT(K, V, long, java.util.concurrent.TimeUnit) ,public final com.alicp.jetcache.CacheResult PUT_ALL(Map<? extends K,? extends V>, long, java.util.concurrent.TimeUnit) ,public final com.alicp.jetcache.CacheResult PUT_IF_ABSENT(K, V, long, java.util.concurrent.TimeUnit) ,public final com.alicp.jetcache.CacheResult REMOVE(K) ,public final com.alicp.jetcache.CacheResult REMOVE_ALL(Set<? extends K>) ,public void close() ,public final V computeIfAbsent(K, Function<K,V>, boolean) ,public final V computeIfAbsent(K, Function<K,V>, boolean, long, java.util.concurrent.TimeUnit) ,public boolean isClosed() ,public void notify(com.alicp.jetcache.event.CacheEvent) <variables>protected volatile boolean closed,private volatile ConcurrentHashMap<java.lang.Object,com.alicp.jetcache.AbstractCache.LoaderLock> loaderMap,private static Logger logger,private static final java.util.concurrent.locks.ReentrantLock reentrantLock