package com.qmth.themis.business.cache;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.qmth.themis.business.cache.bean.ObjectiveAnswerCacheBean;
import com.qmth.themis.business.constant.SpringContextHolder;
import com.qmth.themis.business.util.RedisUtil;

/**客观题缓存
 * @Description: 
 * @Author: xiatian
 * @Date: 2020-12-29
 */
public class ObjectiveAnswerCacheUtil {

    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
    
    public static void saveObjectiveAnswerCache(Long examId,Long paperId,Map<String, ObjectiveAnswerCacheBean> val) {
    	redisUtil.set(RedisKeyHelper.objectiveAnswerCacheKey(examId), RedisKeyHelper.objectiveAnswerCacheHashKey(paperId),val);
    }
    
    public static void expireObjectiveAnswerCache(Long examId,Long hours) {
    	redisUtil.expire(RedisKeyHelper.objectiveAnswerCacheKey(examId), hours, TimeUnit.HOURS);
    }
    
    public static void deleteObjectiveAnswerCache(Long examId,Long paperId) {
    	redisUtil.delete(RedisKeyHelper.objectiveAnswerCacheKey(examId), RedisKeyHelper.objectiveAnswerCacheHashKey(paperId));
    }
    
    @SuppressWarnings("unchecked")
	public static Map<String, ObjectiveAnswerCacheBean> getObjectiveAnswerCache(Long examId,Long paperId) {
    	return (Map<String, ObjectiveAnswerCacheBean>)redisUtil.get(RedisKeyHelper.objectiveAnswerCacheKey(examId), RedisKeyHelper.objectiveAnswerCacheHashKey(paperId));
    }
    
    public static Long getHashCacheSize(Long examId) {
    	Long ret=redisUtil.getHashSize(RedisKeyHelper.objectiveAnswerCacheKey(examId));
    	if(ret==null) {
    		return 0L;
    	}else {
    		return ret;
    	}
    }

}
