package enkan.middleware.session;

import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.configuration.Configuration;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.spi.CachingProvider;
import java.io.Serializable;
import java.util.UUID;

/**
 * @author kawasima
 */
public class JCacheStore implements KeyValueStore {
    private Cache<String, Serializable> cache;

    public JCacheStore() {
        CachingProvider cachingProvider = Caching.getCachingProvider();
        CacheManager cacheManager = cachingProvider.getCacheManager();

        Configuration<String, Serializable> config = new MutableConfiguration<String, Serializable>()
                .setTypes(String.class, Serializable.class);
        cache = cacheManager.getCache("session", String.class, Serializable.class);
        if (cache == null)
            cache = cacheManager.createCache("session", config);
    }

    @Override
    public Serializable read(String key) {
        return cache.get(key);
    }

    @Override
    public String write(String key, Serializable value) {
        if (key == null) {
            key = UUID.randomUUID().toString();
        }
        cache.put(key, value);
        return key;
    }

    @Override
    public String delete(String key) {
        cache.remove(key);
        return key;
    }
}

@@ -196,36 +196,118 @@
 uration.
-MutableConfiguration
+Factory;%0Aimport javax.cache.configuration.MutableConfiguration;%0Aimport javax.cache.expiry.ExpiryPolicy
 ;%0Aimport
@@ -544,24 +544,119 @@
 heStore() %7B%0A
+        this(null);%0A    %7D%0A%0A    public JCacheStore(Factory%3CExpiryPolicy%3E expiryPolicyFactory) %7B%0A
         Cach
@@ -795,16 +795,23 @@
         
+Mutable
 Configur
@@ -949,32 +949,149 @@
 lizable.class);%0A
+        if (expiryPolicyFactory != null) %7B%0A            config.setExpiryPolicyFactory(expiryPolicyFactory);%0A        %7D%0A
         cache = 

Add expires to JCacheStore