com.landawn.abacus.cache.CacheFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-android Show documentation
Show all versions of abacus-android Show documentation
A general and simple library for Android
/*
* Copyright (C) 2015 HaiYang Li
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.landawn.abacus.cache;
import static com.landawn.abacus.cache.DistributedCacheClient.DEFAULT_TIMEOUT;
import com.landawn.abacus.parser.ParserFactory;
import com.landawn.abacus.util.ClassUtil;
import com.landawn.abacus.util.N;
import com.landawn.abacus.util.StringUtil;
import com.landawn.abacus.util.TypeAttrParser;
/**
*
* @since 0.8
*
* @author Haiyang Li
*/
public final class CacheFactory {
private CacheFactory() {
}
public static LocalCache createLocalCache(final int capacity, final long evictDelay) {
return new LocalCache(capacity, evictDelay);
}
/**
*
* @param capacity
* @param evictDelay
* @param defaultLiveTime default value is 3 hours
* @param defaultMaxIdleTime default value is 30 minutes
* @return
*/
public static LocalCache createLocalCache(final int capacity, final long evictDelay, final long defaultLiveTime,
final long defaultMaxIdleTime) {
return new LocalCache(capacity, evictDelay, defaultLiveTime, defaultMaxIdleTime);
}
public static DistributedCache createDistributedCache(final DistributedCacheClient dcc) {
return new DistributedCache(dcc);
}
public static DistributedCache createDistributedCache(final DistributedCacheClient dcc, final String keyPrefix) {
return new DistributedCache(dcc, keyPrefix);
}
public static DistributedCache createDistributedCache(final DistributedCacheClient dcc, final String keyPrefix,
final int maxFailedNumForRetry, final long retryDelay) {
return new DistributedCache(dcc, keyPrefix, maxFailedNumForRetry, retryDelay);
}
@SuppressWarnings("unchecked")
public static Cache createCache(final String provider) {
TypeAttrParser attrResult = TypeAttrParser.parse(provider);
String[] parameters = attrResult.getParameters();
String url = parameters[0];
String className = attrResult.getClassName();
Class> cls = null;
if (DistributedCacheClient.MEMCACHED.equalsIgnoreCase(className)) {
final net.spy.memcached.transcoders.Transcoder