/** * 安全添加数据 * * @param key * @param value * @param expiration * @return */ public static boolean safeAdd(String key, Object value, int expiration) { checkSerializable(value); Logger.info( "add '%s - %s' into cache for '%s' seconds!", key, Strings.toString(value), expiration); if (getImpl().safeAdd(key, value, expiration)) { return true; } Logger.warn("add '%s - %s' into cache failure!", key, Strings.toString(value)); return false; }
/** * 检查值是否序列化 * * @param value */ protected static void checkSerializable(Object value) { if (value != null && !(value instanceof Serializable)) { throw new ServiceException( String.format("the object '%s' is not serialized.", Strings.toString(value)), "exception.serialize"); } }
/** * 添加数据 * * @param key * @param value * @param expiration */ public static void add(String key, Object value, int expiration) { checkSerializable(value); Logger.info( "add '%s - %s' into cache for '%s' seconds!", key, Strings.toString(value), expiration); getImpl().add(key, value, expiration); }