isPoolInitialized = true;
}
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
CacheResult annotation = getCacheResultAnnotation(invocation);
if (annotation != null) {
if (!isPoolInitialized) {
initializePool();
}
MemcachedClient memcached = pool.getClient();
String cacheKey = annotation.cacheKey().equals("") ? getCacheKey(invocation, isUsingRawKey()) : annotation.cacheKey();
Object cachedObject = null;
try {
cachedObject = memcached.get(cacheKey);
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug("Failed to get a value from memcached servers. (" + cacheKey + ")", t);
}
}
if (cachedObject != null) {
return cachedObject;
} else {
Object value = invocation.proceed();
try {
memcached.set(cacheKey, annotation.secondsToExpire(), value);
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug("Failed to set a value to memcached servers. (" + cacheKey + " -> " + value + ")", t);
}
}