All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nutz.plugins.cache.impl.ehcache.EhcacheCacheManager Maven / Gradle / Ivy

There is a newer version: 1.r.69.v20220215
Show newest version
package org.nutz.plugins.cache.impl.ehcache;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheManager;

public class EhcacheCacheManager implements CacheManager {
    
    private byte[] lock = new byte[0];
    
    protected net.sf.ehcache.CacheManager cacheManager;

    public  Cache getCache(String name) {
        return new EhcacheCache(getCache(name, true));
    }

    public void init() {}

    public void depose() {}

    protected net.sf.ehcache.Cache getCache(String name, boolean create) {
        net.sf.ehcache.Cache cache = cacheManager.getCache(name);
        if (cache == null) {
            if (!create)
                return null;
            synchronized (lock) {
                cache = cacheManager.getCache(name);
                if (cache == null) {
                    cacheManager.addCache(name);
                    cache = cacheManager.getCache(name);
                }
            }
        }
        return cache;
    }
    
    public void setCacheManager(net.sf.ehcache.CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy