Commit 3e72d632 by fsn

修改ConstantFactory缓存的key的策略

parent 0c0cef90
package com.stylefeng.guns.common.constant; package com.stylefeng.guns.common.constant.cache;
/** /**
* 所有缓存名称的集合 * 所有缓存名称的集合
......
package com.stylefeng.guns.common.constant.cache;
/**
* 缓存的key集合
*
* @author fengshuonan
* @date 2017-04-25 9:37
*/
public interface CacheKey {
/**
* ConstantFactory中的缓存
*/
String ROLES_NAME = "roles_name_";
String SINGLE_ROLE_NAME = "single_role_name_";
String SINGLE_ROLE_TIP = "single_role_tip_";
String DEPT_NAME = "dept_name_";
}
package com.stylefeng.guns.common.constant.factory; package com.stylefeng.guns.common.constant.factory;
import com.stylefeng.guns.common.constant.Cache; import com.stylefeng.guns.common.constant.cache.Cache;
import com.stylefeng.guns.common.constant.cache.CacheKey;
import com.stylefeng.guns.common.constant.state.ManagerStatus; import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.constant.state.MenuStatus; import com.stylefeng.guns.common.constant.state.MenuStatus;
import com.stylefeng.guns.common.constant.state.Sex; import com.stylefeng.guns.common.constant.state.Sex;
...@@ -29,14 +30,14 @@ public class ConstantFactory { ...@@ -29,14 +30,14 @@ public class ConstantFactory {
private RoleMapper roleMapper = SpringContextHolder.getBean(RoleMapper.class); private RoleMapper roleMapper = SpringContextHolder.getBean(RoleMapper.class);
private DeptMapper deptMapper = SpringContextHolder.getBean(DeptMapper.class); private DeptMapper deptMapper = SpringContextHolder.getBean(DeptMapper.class);
public static ConstantFactory me(){ public static ConstantFactory me() {
return SpringContextHolder.getBean("constantFactory"); return SpringContextHolder.getBean("constantFactory");
} }
/** /**
* 通过角色ids获取角色名称 * 通过角色ids获取角色名称
*/ */
@Cacheable(Cache.CONSTANT) @Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) { public String getRoleName(String roleIds) {
Integer[] roles = Convert.toIntArray(roleIds); Integer[] roles = Convert.toIntArray(roleIds);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -52,7 +53,7 @@ public class ConstantFactory { ...@@ -52,7 +53,7 @@ public class ConstantFactory {
/** /**
* 通过角色id获取角色名称 * 通过角色id获取角色名称
*/ */
@Cacheable(Cache.CONSTANT) @Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId")
public String getSingleRoleName(Integer roleId) { public String getSingleRoleName(Integer roleId) {
if (0 == roleId) { if (0 == roleId) {
return "--"; return "--";
...@@ -67,7 +68,7 @@ public class ConstantFactory { ...@@ -67,7 +68,7 @@ public class ConstantFactory {
/** /**
* 通过角色id获取角色英文名称 * 通过角色id获取角色英文名称
*/ */
@Cacheable(Cache.CONSTANT) @Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId")
public String getSingleRoleTip(Integer roleId) { public String getSingleRoleTip(Integer roleId) {
if (0 == roleId) { if (0 == roleId) {
return "--"; return "--";
...@@ -82,7 +83,7 @@ public class ConstantFactory { ...@@ -82,7 +83,7 @@ public class ConstantFactory {
/** /**
* 获取部门名称 * 获取部门名称
*/ */
@Cacheable(Cache.CONSTANT) @Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId")
public String getDeptName(Integer deptId) { public String getDeptName(Integer deptId) {
Dept dept = deptMapper.selectById(deptId); Dept dept = deptMapper.selectById(deptId);
if (ToolUtil.isNotEmpty(dept) && ToolUtil.isNotEmpty(dept.getFullname())) { if (ToolUtil.isNotEmpty(dept) && ToolUtil.isNotEmpty(dept.getFullname())) {
......
package com.stylefeng.guns.modular.system.dao; package com.stylefeng.guns.modular.system.dao;
import com.stylefeng.guns.common.constant.Cache;
import com.stylefeng.guns.persistence.model.Dict; import com.stylefeng.guns.persistence.model.Dict;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.Cacheable;
import java.util.List; import java.util.List;
...@@ -22,6 +20,5 @@ public interface DictDao { ...@@ -22,6 +20,5 @@ public interface DictDao {
* @return * @return
* @date 2017年2月13日 下午11:11:28 * @date 2017年2月13日 下午11:11:28
*/ */
@Cacheable(Cache.CONSTANT)
public List<Dict> selectByCode(@Param("code") String code); public List<Dict> selectByCode(@Param("code") String code);
} }
...@@ -54,9 +54,6 @@ public class CacheTest extends BaseTest{ ...@@ -54,9 +54,6 @@ public class CacheTest extends BaseTest{
System.out.println(); System.out.println();
System.out.println(); System.out.println();
Object constant = CacheKit.get("CONSTANT", 1);
System.out.println(constant);
List constant1 = CacheKit.getKeys("CONSTANT"); List constant1 = CacheKit.getKeys("CONSTANT");
System.out.println(JSON.toJSONString(constant1)); System.out.println(JSON.toJSONString(constant1));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment