志愿中山的缓存使用和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) 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"));
    }

}

 

你可能感兴趣的:(志愿中山的缓存使用和hql的分页)