Package com.liosha.services

Source Code of com.liosha.services.ApplicationCacheServiceImpl

package com.liosha.services;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import org.springframework.stereotype.Component;

@Component("applicationCacheService")
public class ApplicationCacheServiceImpl implements ApplicationCacheService {

    public void put(String key, Object item) {
        CacheManager cacheManager = CacheManager.getInstance();
        Cache cache = cacheManager.getCache("generalUseCache");
        cache.put(new Element(key, item));
    }

    public Object get(String key) {
        CacheManager cacheManager = CacheManager.getInstance();
        Cache cache = cacheManager.getCache("generalUseCache");
        Element element = cache.get(key);
        return (element == null) ? null : element.getObjectValue();
    }

    public void delete(String key) {
        CacheManager cacheManager = CacheManager.getInstance();
        Cache cache = cacheManager.getCache("generalUseCache");
        cache.remove(key);
    }

    public void clear() {
        CacheManager cacheManager = CacheManager.getInstance();
        Cache cache = cacheManager.getCache("generalUseCache");
        cache.removeAll();
    }
}
TOP

Related Classes of com.liosha.services.ApplicationCacheServiceImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.