Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Spring aop + xmemcached configure service layer caching policy

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

< args.length; i++) { sb.append(classTemps[i] + "&"); if (null == args[i]) { sb.append("null"); } else if ("".equals(args[i])) { sb.append("*"); } else { String tt = JSON.toJSONString(args[i]); sb.append(tt); } } sb.append(key); sb.append(version.toString()); String temp = Md5Utils.getMD5(sb.toString()); return temp; }} 4,properties文件中配置memcached服务器地址 #host1:port1,host2:port2memcached.servers=192.168.1.1:11211,192.168.1.2:11211 5,修改spring配置文件,声明自动为spring容器中那些配置@aspectJ切面的bean创建代理,织入切面。 6,service层使用注解方式切入缓存 import java.util.Arrays;import java.util.Date;import java.util.List;import java.util.Map;import org.apache.ibatis.session.RowBounds;import org.apache.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import com.alibaba.dubbo.common.utils.StringUtils;import com.alibaba.dubbo.config.annotation.Service;import com.node.hlhw.common.cache.XmemCache;import com.node.hlhw.common.digest.ApplicationUtils;import com.node.hlhw.core.service.BaseService;import com.node.hlhw.core.store.IBaseStore;import com.node.hlhw.core.store.PageParam;import com.node.hlhw.rbac.api.dao.UserRoleDao;import com.node.hlhw.rbac.api.entity.UserRole;import com.node.hlhw.rbac.api.service.UserRoleService;/** * @author Melody * 处理用户角色 */@Service(version = "1.0.0")public class UserRoleServiceImpl extends BaseService implements UserRoleService { private static final Logger logger = Logger .getLogger(UserRoleServiceImpl.class); @Autowired public UserRoleDao userRoleDao; @Override protected IBaseStore getBaseDao() { return userRoleDao; } /* * 单表操作,prefix为表名,operation为4,只进行缓存的删除操作 */ @XmemCache(prefix="userrole",operation=4) public void insertUserRole(UserRole userRole) throws Exception { userRoleDao.insertUserRole(userRole); logger.info("插入用户角色数据"); } /* (non-Javadoc) * 此方法操作了两个表,role与userole,使用'|'进行分隔 * operation为1,表示缓存操作,对结果集进行缓存 * interval表示缓存时间默认不填为3600秒,也可指定具体时长 */ @Override @XmemCache(prefix="role|userrole",interval=3600 , operation=1) public List selectUserRoleList(UserRole userrole, PageParam pageParam) throws Exception { RowBounds rowBounds = new RowBounds(pageParam.getOffset(),pageParam.getLimit()); List list = userRoleDao.selectUserRoleList(userrole,rowBounds); return list ; } @Override @XmemCache(prefix="userrole" , operation=4) public void modifyUserRole(UserRole userrole, String[] roleids)throws Exception { //删除所包含的角色 userRoleDao.deleteByUserRole(userrole); for(String roleid : roleids){ if(!StringUtils.isEmpty(roleid)){ userrole.setCreatetime(new Date()); userrole.setRoleid(roleid); userrole.setUuid(ApplicationUtils.getUUID()); userRoleDao.insertUserRole(userrole); } } } @Override @XmemCache(prefix="userrole" , operation=1) public boolean existsRef(String roleids)throws Exception { String [] roleid = roleids.split(","); List roleidlist = Arrays.asList(roleid); return userRoleDao.existsRef(roleidlist)>

0 true true false;}}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report