
com.alicp.jetcache.external.AbstractExternalCache Maven / Gradle / Ivy
The newest version!
package com.alicp.jetcache.external;
import com.alicp.jetcache.AbstractCache;
import com.alicp.jetcache.CacheConfigException;
import com.alicp.jetcache.CacheException;
import com.alicp.jetcache.RefreshCache;
import com.alicp.jetcache.anno.KeyConvertor;
import java.io.IOException;
/**
* Created on 2016/10/8.
*
* @author huangli
*/
public abstract class AbstractExternalCache extends AbstractCache {
private ExternalCacheConfig config;
public AbstractExternalCache(ExternalCacheConfig 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy