EhCache3 + Spring Boot 2 без XML - PullRequest
       20

EhCache3 + Spring Boot 2 без XML

0 голосов
/ 10 февраля 2020

Я застрял, находя решение, как реализовать EhCache3 с Spring Boot 2. Проблема в том, что в версии 3 они изменили пакет на org.ehcache, и примеры конфигурации, не обнаруженной xml, которые я обнаружил, предназначены для версии 2, где вы объявляете net .sf.ehcache.config. и я хочу работать с 3-й версией.

 package com.jcg.example.ehcache_no_xml.config;

import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import net.sf.ehcache.Cache;
import net.sf.ehcache.config.CacheConfiguration;

@Configuration
public class EhCacheConfig {

    @Bean
    public EhCacheManagerFactoryBean cacheManager() {
        return new EhCacheManagerFactoryBean();
    }

    @Bean
    public EhCacheCacheManager testEhCacheManager() {
        // testEhCache Configuration - create configuration of cache that previous required XML
        CacheConfiguration testEhCacheConfig = new CacheConfiguration()
            .eternal(false)                     // if true, timeouts are ignored
            .timeToIdleSeconds(3)               // time since last accessed before item is marked for removal
            .timeToLiveSeconds(5)               // time since inserted before item is marked for removal
            .maxEntriesLocalHeap(10)            // total items that can be stored in cache
            .memoryStoreEvictionPolicy("LRU")   // eviction policy for when items exceed cache. LRU = Least Recently Used
            .name("testCache");

        Cache testCache = new Cache(testEhCacheConfig);

        cacheManager().getObject().addCache(testCache);
        return new EhCacheCacheManager(cacheManager().getObject());
    }
}

Есть ли какое-нибудь решение, как создать конфигурацию ehCache с помощью пружины?

...