当前位置: 首页 > 工具软件 > OSCache > 使用案例 >

OSCache

万修为
2023-12-01
public class BaseCache extends GeneralCacheAdministrator {
    private static final long serialVersionUID = 1L;

    public void putCache(String key, Object content){
        this.putInCache(key, content);
    }

    public Object getCache(String key){
        try {

            return this.getFromCache(key,36000);

        } catch (NeedsRefreshException e) {
            e.printStackTrace();
            return null;
        }
    }
}


public class CacheServiceImpl extends AbstractService implements CacheService {

    @Autowired
    private BaseCache baseCache;
    @Autowired
    private ListingService listingService;

    //分类加到缓存
    @Override
    public List getCategoryFromCache(Map params){
        String site=params.get("site").toString();
        String level=(String)params.get("level");
        String cid=(String)params.get("cid");

        Object object=null;
        boolean isLevel=true;
        if(!"".equals(level) && null!=level){

            object=baseCache.getCache("category_"+site+"_"+level);
        }else{

            object=baseCache.getCache("category_"+site+"_"+cid);
            isLevel=false;
        }
        if(object!=null)
            return (List) object;  
        }else{ 
            List categoryList=listingService.getCategoryOne(params);
            if(isLevel){
                baseCache.putCache("category_"+site+"_"+level, categoryList);
            }else{
                baseCache.putCache("category_"+site+"_"+cid, categoryList);
            }

            return categoryList;
        }
    }
 类似资料:

相关阅读

相关文章

相关问答