001    package org.picocontainer.web.caching;
002    
003    import javax.cache.*;
004    import javax.cache.Cache;
005    import java.util.Map;
006    import java.util.HashMap;
007    
008    import org.picocontainer.injectors.ProviderAdapter;
009    import org.picocontainer.web.*;
010    
011    public class JCacheProvider extends ProviderAdapter {
012    
013        private static final Map props = new HashMap();
014        static {
015            // com.google.appengine.api.memcache.stdimpl.GCacheFactory.EXPIRATION_DELTA (yeesh) == 0
016            // 120 == 1 min
017            props.put(0, 120);        
018        }
019    
020        public org.picocontainer.web.Cache provide() throws CacheException {
021            CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
022            final javax.cache.Cache jCache = cacheFactory.createCache(props);
023            return new org.picocontainer.web.Cache() {
024                public Object get(Object key) {
025                    return jCache.get(key);
026                }
027                public void put(Object key, Object toCache) {
028                    jCache.put(key, toCache);
029                }
030            };
031        }
032    }