package cn.com.qmth.examcloud.web.cache; import java.util.Map; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.google.common.collect.Maps; import cn.com.qmth.examcloud.api.commons.CloudService; import cn.com.qmth.examcloud.commons.exception.StatusException; import cn.com.qmth.examcloud.commons.logging.ExamCloudLog; import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory; import cn.com.qmth.examcloud.commons.util.JsonUtil; import cn.com.qmth.examcloud.web.support.SpringContextHolder; /** * cache * * @author WANGWEI * @date 2018年8月23日 * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved. */ @RestController @RequestMapping("cache") public class CacheCloudServiceProvider implements CloudService { private static final long serialVersionUID = -5326807830421467943L; protected static final ExamCloudLog LOG = ExamCloudLogFactory .getLog(CacheCloudServiceProvider.class); private static Map> map = Maps.newConcurrentMap(); @RequestMapping(value = "refresh", method = RequestMethod.POST) public String refresh(@RequestBody RefreshCacheReq req) { String className = req.getClassName(); Object[] keys = req.getKeys(); ObjectCache objectCache = map.get(className); if (null == objectCache) { try { Class c = Class.forName(className); objectCache = (ObjectCache) SpringContextHolder.getBean(c); map.put(className, objectCache); } catch (ClassNotFoundException e) { throw new StatusException("008001", "class not found"); } } objectCache.refresh(keys); Object object = objectCache.get(keys); return JsonUtil.toJson(object); } }