CacheKeyEnum.java 1.61 KB
/**
 * 
 */
package com.yohoufo.user.cache;

import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.TimeUnit;

/**
 * 描述:
 * 
 * @author craig.qin 2018年9月17日
 */
public enum CacheKeyEnum {

	// user - passport -authorize
	AUTHORIZE_FAILED_KEY("ufo:user:authorizeFailed:",  "实名认证失败次数", 30, TimeUnit.MINUTES),
	AUTHORIZE_INFO_KEY("ufo:user:authorizeInfo:","实名认证信息", 2, TimeUnit.HOURS),

	ZHI_MA_CERT_KEY("ufo:user:zhiMaCert:","芝麻认证信息", 2, TimeUnit.HOURS),

	STORED_SELLER_KEY("ufo:user:storedSeller:","商家入驻信息", 2, TimeUnit.HOURS),

	USER_PRODUCT_FAVORITE_ZSET_KEY("ufo:user:product:favorite:","用户商品收藏集合", 180, TimeUnit.DAYS),
	;

	// 缓存的key
	private String cacheKey;

	private String desc;

	// 默认的过期时间
	private int defaultExpireTime;

	// 缓存时间单位
	private TimeUnit timeUnit;


	CacheKeyEnum(String cacheKey,  String desc, int defaultExpireTime, TimeUnit timeUnit) {
		this.cacheKey = cacheKey;
		this.desc = desc;
		this.defaultExpireTime = defaultExpireTime;
		this.timeUnit = timeUnit;
	}

	/**
	 * 获取该枚举的信息
	 * 
	 * @param key
	 * @return
	 */
	public static CacheKeyEnum getEnumByKey(String key) {
		if (StringUtils.isEmpty(key)) {
			return null;
		}
		for (CacheKeyEnum e : values()) {
			if (key.equalsIgnoreCase(e.name())) {
				return e;
			}
		}
		return null;
	}

	public String getCacheKey() {
		return cacheKey;
	}

	public int getDefaultExpireTime() {
		return defaultExpireTime;
	}

	public TimeUnit getTimeUnit() {
		return timeUnit;
	}

	public String getDesc() {
		return desc;
	}

}