志愿中山的缓存使用和hql的分页

    /**
     * . 分页查询 BY  HQL
     *
     * @param queryString :hql语句
     * @return list
     * @author 梁文敏
     **/
    public List findByHqlByLimit(String queryString,int frist,int end) {
        LOG.debug("finding by hql:" + queryString);
        List list = null;
        try {

            Query query = em.createQuery(queryString).setFirstResult(frist).setMaxResults(end);
            list = query.getResultList();
        } catch (RuntimeException re) {
            LOG.error("find by hql failed", re);
            throw re;
        }

        return list;
    }

缓存使用

String cacheKey = "ZYZS_TEAM_ORG_DETAIL_" + orgDetailVo.getOrgId();
            result = (RetResult<OrgTeamStatDetailDto>) CacheManager.getInstance().getCacheDataByKey(cacheKey);
            if(result==null){
                result = orgMergeService.orgTeamStatDetail(orgDetailVo);
                CacheManager.getInstance().putCache(cacheKey, result, 30);
            }

缓存方法  import java.util.concurrent.TimeUnit;

package com.zhongkai.jupiter.cache;

import java.util.concurrent.TimeUnit;

public class CacheManager {
    private static ICacheManager iCacheManager = null;

    static public ICacheManager getInstance() {
        if (iCacheManager == null) {
            iCacheManager = new CacheManagerImpl();
            CacheListener cacheListener = new CacheListener(iCacheManager);
            cacheListener.startListen();
        }
        return iCacheManager;
    }

    public static void main(String[] args) {
        CacheManager.getInstance().putCache("11111", "333333", 1);
        System.out.println(CacheManager.getInstance().getCacheDataByKey("11111"));
        try {
            TimeUnit.SECONDS.sleep(120);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(CacheManager.getInstance().getCacheDataByKey("11111"));
    }

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值